From 6bdb096e1bccbcac640d3c7ca06f9563acd19b48 Mon Sep 17 00:00:00 2001 From: codegirl-007 Date: Sat, 27 Jun 2026 23:11:18 -0700 Subject: [PATCH] test for math2d and wave --- game/math2d_test.odin | 62 +++++++++++++++++++++++++++++++++++++++++++ game/wave_test.odin | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 game/math2d_test.odin create mode 100644 game/wave_test.odin diff --git a/game/math2d_test.odin b/game/math2d_test.odin new file mode 100644 index 0000000..39d241f --- /dev/null +++ b/game/math2d_test.odin @@ -0,0 +1,62 @@ +package game + +import "core:math" +import "core:testing" + +@(test) +test_distance :: proc(t: ^testing.T) { + a := Vec2 { + x = 3, + y = 2, + } + b := Vec2 { + x = 1, + y = 2, + } + + d := distance(a, b) + + testing.expect(t, math.abs(d - 2.0) < 0.0001) +} + +@(test) +test_move_toward_already_close :: proc(t: ^testing.T) { + pos := Vec2{0.5, 0} + target := Vec2{0, 0} + + move_toward(&pos, target, 10, 1.0) + + testing.expect(t, math.abs(pos.x - 0.5) < 0.0001) + testing.expect(t, math.abs(pos.y - 0.0) < 0.0001) +} + +@(test) +test_move_toward_reaches_target :: proc(t: ^testing.T) { + pos := Vec2{0, 0} + target := Vec2{3, 4} + + move_toward(&pos, target, 100, 1.0) + + testing.expect(t, math.abs(pos.x - 3) < 0.0001) + testing.expect(t, math.abs(pos.y - 4) < 0.0001) +} + +@(test) +test_move_toward_partial :: proc(t: ^testing.T) { + pos := Vec2{0, 0} + target := Vec2{10, 0} + + move_toward(&pos, target, 2, 1.0) + + testing.expect(t, math.abs(pos.x - 2) < 0.0001) + testing.expect(t, math.abs(pos.y) < 0.0001) +} + +@(test) +test_move_toward_diagonal :: proc(t: ^testing.T) { + pos := Vec2{0, 0} + target := Vec2{3, 4} + + move_toward(&pos, target, 5, 0.5) +} + diff --git a/game/wave_test.odin b/game/wave_test.odin new file mode 100644 index 0000000..e8601c3 --- /dev/null +++ b/game/wave_test.odin @@ -0,0 +1,59 @@ +package game + +import "core:testing" + +@(test) +test_start_wave_enters_combat :: proc(t: ^testing.T) { + world := World { + phase = .Combat, + } + world.wave.current_wave = 0 + + start_wave(&world) + + testing.expect(t, world.phase == .Combat) + testing.expect(t, world.wave.current_wave == 0) +} + +@(test) +test_start_wave_from_build :: proc(t: ^testing.T) { + world := World { + phase = .Build, + } + world.wave.current_wave = 0 + + start_wave(&world) + + testing.expect(t, world.phase == .Combat) + testing.expect(t, world.wave.current_wave == 1) + testing.expect(t, world.wave.spawner.spawn_timer == 0) + testing.expect(t, world.wave.spawner.spawn_interval == 0.55) + testing.expect(t, world.wave.spawner.recipe_index == 0) +} + +@(test) +test_clear_wave_not_cleared :: proc(t: ^testing.T) { + world := World{} + world.wave.spawner.recipe = make([dynamic]Wave_Entry, context.allocator) + append(&world.wave.spawner.recipe, Wave_Entry{}) + defer delete(world.wave.spawner.recipe); world.wave.spawner.recipe_index = 0 + world.wave.spawner.entry_remaining = 0 + + result := clear_wave(&world) + + testing.expect(t, result == false) +} + +@(test) +test_clear_wave_cleared :: proc(t: ^testing.T) { + world := World{} + world.wave.spawner.recipe = make([dynamic]Wave_Entry, context.allocator) + append(&world.wave.spawner.recipe, Wave_Entry{}) + defer delete(world.wave.spawner.recipe); world.wave.spawner.recipe_index = 1 + world.wave.spawner.entry_remaining = 0 + + result := clear_wave(&world) + + testing.expect(t, result == true) +} +