146 lines
3.4 KiB
Odin
146 lines
3.4 KiB
Odin
package game
|
|
|
|
import "core:testing"
|
|
|
|
@(test)
|
|
test_start_wave_enters_combat :: proc(t: ^testing.T) {
|
|
world := World {
|
|
phase = .Combat,
|
|
}
|
|
world.wave = 0
|
|
|
|
start_wave(&world)
|
|
|
|
testing.expect(t, world.phase == .Combat)
|
|
testing.expect(t, world.wave == 0)
|
|
}
|
|
|
|
@(test)
|
|
test_start_wave_from_build :: proc(t: ^testing.T) {
|
|
world := World {
|
|
phase = .Build,
|
|
}
|
|
world.wave = 0
|
|
|
|
start_wave(&world)
|
|
defer delete(world.spawner.recipe)
|
|
|
|
testing.expect(t, world.phase == .Combat)
|
|
testing.expect(t, world.wave == 1)
|
|
testing.expect(t, world.spawner.spawn_timer == 0)
|
|
testing.expect(t, world.spawner.spawn_interval == 0.55)
|
|
testing.expect(t, world.spawner.recipe_index == 0)
|
|
}
|
|
|
|
@(test)
|
|
test_clear_wave_not_cleared :: proc(t: ^testing.T) {
|
|
world := World{}
|
|
world.spawner.recipe = make([dynamic]Wave_Entry, context.allocator)
|
|
append(&world.spawner.recipe, Wave_Entry{})
|
|
defer delete(world.spawner.recipe)
|
|
world.spawner.recipe_index = 0
|
|
world.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.spawner.recipe = make([dynamic]Wave_Entry, context.allocator)
|
|
append(&world.spawner.recipe, Wave_Entry{})
|
|
defer delete(world.spawner.recipe)
|
|
world.spawner.recipe_index = 1
|
|
world.spawner.entry_remaining = 0
|
|
|
|
result := clear_wave(&world)
|
|
|
|
testing.expect(t, result == true)
|
|
}
|
|
|
|
@(test)
|
|
test_update_wave_ignores_build_phase :: proc(t: ^testing.T) {
|
|
world := init_world()
|
|
defer delete(world.path)
|
|
world.phase = .Build
|
|
world.spawner.spawn_timer = 0
|
|
world.spawner.entry_remaining = 5
|
|
|
|
update_wave(&world, 1.0)
|
|
|
|
testing.expect(t, active_enemy_count(&world) == 0)
|
|
}
|
|
|
|
@(test)
|
|
test_update_wave_waits_for_spawn_timer :: proc(t: ^testing.T) {
|
|
world := init_world()
|
|
defer delete(world.path)
|
|
world.phase = .Combat
|
|
world.spawner.recipe = make([dynamic]Wave_Entry, context.allocator)
|
|
append(&world.spawner.recipe, Wave_Entry{.Grunt, 1})
|
|
defer delete(world.spawner.recipe)
|
|
world.spawner.recipe_index = 0
|
|
world.spawner.entry_remaining = 1
|
|
world.spawner.spawn_timer = 0.5
|
|
|
|
update_wave(&world, 0.1)
|
|
|
|
testing.expect(t, active_enemy_count(&world) == 0)
|
|
testing.expect(t, world.spawner.spawn_timer == 0.4)
|
|
}
|
|
|
|
@(test)
|
|
test_update_wave_spawns_and_resets_timer :: proc(t: ^testing.T) {
|
|
world := init_world()
|
|
defer delete(world.path)
|
|
world.phase = .Combat
|
|
world.wave = 1
|
|
world.spawner.recipe = make([dynamic]Wave_Entry, context.allocator)
|
|
append(&world.spawner.recipe, Wave_Entry{.Grunt, 2})
|
|
defer delete(world.spawner.recipe)
|
|
world.spawner.recipe_index = 0
|
|
world.spawner.entry_remaining = 2
|
|
world.spawner.spawn_timer = 0
|
|
world.spawner.spawn_interval = 0.55
|
|
|
|
update_wave(&world, 0.55)
|
|
|
|
testing.expect(t, active_enemy_count(&world) == 1)
|
|
testing.expect(t, world.spawner.entry_remaining == 1)
|
|
testing.expect(t, world.spawner.spawn_timer == 0.55)
|
|
|
|
found_grunt := false
|
|
for i in 0 ..< MAX_ENEMIES {
|
|
if world.enemies[i].active {
|
|
testing.expect(t, world.enemies[i].kind == .Grunt)
|
|
found_grunt = true
|
|
}
|
|
}
|
|
testing.expect(t, found_grunt)
|
|
}
|
|
|
|
@(test)
|
|
test_update_phase_from_build_phase :: proc(t: ^testing.T) {
|
|
world := World{}
|
|
defer delete(world.events)
|
|
|
|
world.phase = .Build
|
|
update_phase(&world)
|
|
|
|
testing.expect(t, world.phase == .Build)
|
|
}
|
|
|
|
@(test)
|
|
test_update_phase_from_combat_phase :: proc(t: ^testing.T) {
|
|
world := World{}
|
|
defer delete(world.events)
|
|
world.phase = .Combat
|
|
|
|
update_phase(&world)
|
|
|
|
testing.expect(t, world.phase == .Build)
|
|
}
|
|
|