-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.lua
More file actions
71 lines (66 loc) · 2.41 KB
/
Copy pathtests.lua
File metadata and controls
71 lines (66 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- tests.lua
-- Busted tests for logic.lua (Tower Defense Resource Game)
-- See README.md for documentation and usage.
local logic = require 'logic'
describe('logic.dist', function()
it('returns correct Euclidean distance', function()
assert.is_true(math.abs(logic.dist(0,0,3,4) - 5) < 1e-6)
assert.is_true(math.abs(logic.dist(1,2,1,2) - 0) < 1e-6)
end)
end)
describe('logic.can_collect', function()
it('returns true if player is within radius and resource is active', function()
local player = {x=0, y=0}
local src = {x=0, y=10, active=true}
assert.is_true(logic.can_collect(player, src, 15))
end)
it('returns false if resource is inactive', function()
local player = {x=0, y=0}
local src = {x=0, y=10, active=false}
assert.is_false(logic.can_collect(player, src, 15))
end)
it('returns false if player is out of radius', function()
local player = {x=0, y=0}
local src = {x=0, y=20, active=true}
assert.is_false(logic.can_collect(player, src, 15))
end)
end)
describe('logic.tower_select_ammo', function()
it('selects highest damage ammo available', function()
local ammo = {wood=1, stone=2}
local RESOURCE_DAMAGE = {wood=1, grass=2, stone=3, metal=4}
local t, dmg = logic.tower_select_ammo(ammo, RESOURCE_DAMAGE)
assert.are.equal('stone', t)
assert.are.equal(3, dmg)
end)
it('returns nil if no ammo', function()
local ammo = {}
local RESOURCE_DAMAGE = {wood=1, grass=2, stone=3, metal=4}
local t, dmg = logic.tower_select_ammo(ammo, RESOURCE_DAMAGE)
assert.is_nil(t)
assert.are.equal(0, dmg)
end)
end)
describe('logic.enemy_find_nearest_resource', function()
it('finds the closest active resource', function()
local enemy = {x=0, y=0}
local resource_sources = {
{x=10, y=0, active=true},
{x=100, y=0, active=true},
{x=5, y=0, active=false}
}
local RESOURCE_SIZE, ENEMY_SIZE = 0, 0
local src, dist = logic.enemy_find_nearest_resource(enemy, resource_sources, RESOURCE_SIZE, ENEMY_SIZE)
assert.are.equal(resource_sources[1], src)
end)
it('returns nil if no active resources', function()
local enemy = {x=0, y=0}
local resource_sources = {
{x=10, y=0, active=false},
{x=100, y=0, active=false}
}
local RESOURCE_SIZE, ENEMY_SIZE = 0, 0
local src, dist = logic.enemy_find_nearest_resource(enemy, resource_sources, RESOURCE_SIZE, ENEMY_SIZE)
assert.is_nil(src)
end)
end)