add preliminary tests for wave
This commit is contained in:
@@ -59,3 +59,85 @@ test_clear_wave_cleared :: proc(t: ^testing.T) {
|
||||
|
||||
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{}
|
||||
world.phase = .Build
|
||||
|
||||
update_phase(&world)
|
||||
|
||||
testing.expect(t, world.phase == .Build)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_udpate_phase_from_combat_phase :: proc(t: ^testing.T) {
|
||||
world := World{}
|
||||
world.phase = .Combat
|
||||
|
||||
update_phase(&world)
|
||||
|
||||
testing.expect(t, world.phase == .Build)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user