-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.lua
181 lines (156 loc) · 6.54 KB
/
tests.lua
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
--[[
---------------------------------------------
test.lua
by Caio Madeira
Module for test mod and Teardown API functions.
All functions start with test.
---------------------------------------------
]]--
--[[
******************************************************************
NOTE: I have a problem. I want to get name functions, but
dosent have an bult-in solution for this. So, i leave it here to
elaborate futhermore.
*****************************************************************
UnitTestsRegistry = {
RandomizePrefabPropertyTests = {
functable1_ShouldReturnStrType = {
name = "test_RandomizePrefabProperty_ShouldReturnStrType"
},
metatable1_ShouldReturnStrType = { },
}
}
UnitTestsRegistry.RandomizePrefabPropertyTests.metatable1_ShouldReturnStrType.__call = function ()
print "test"
end
setmetatable(
UnitTestsRegistry.RandomizePrefabPropertyTests.functable1_ShouldReturnStrType,
UnitTestsRegistry.RandomizePrefabPropertyTests.metatable1_ShouldReturnStrType
)
UnitTestsRegistry.RandomizePrefabPropertyTests.functable1_ShouldReturnStrType()
print(">>>" .. UnitTestsRegistry.RandomizePrefabPropertyTests.functable1_ShouldReturnStrType.name)
]] --
require('settings')
if MOD.TESTS then
require('sources.prefab')
require('sources.commons.constants')
require('sources.utils')
luaunit = require('lib.luaunit')
-- Set local function simulating a private function
-- in this case local functions are ignored by luaunit
-- so, i can call this in another file if i want to test the API
local function testVecAdd(a, b)
print(":::::: " .. "testVecAdd()" .. " ::::::")
local a = { 2, 3, 2}
local b = { 1, 1, 1}
if #a ~= 3 and #b ~= 3 then
error("One of vectors not have three values.")
end
local c = VecAdd(a, b)
print("Sum of vector a and b: " .. VecStr(c))
print(":::::::::::::::::::::::::::::::::::::::")
end
--[[
**********************************************
CalculateCubeTotalArea()
**********************************************
]]--
function test_CalculateCubeTotalArea()
local side = 150
local f = CalculateCubeTotalArea(side)
print("\n")
print("Init Function output:")
print("> test_CalculateCubeTotalArea")
print("-----------------------")
print("Result: ", f)
print("-----------------------")
print("End Function output:")
print("\n")
if side == 7 then
luaunit.assertEquals(f, 294, 'Wrong result.')
elseif side == 150 then
luaunit.assertEquals(f, 135000, 'Wrong result.')
end
end
--[[
**********************************************
ConvertTableToStr()
**********************************************
]]--
function test_ConvertTableToStr_ShouldReturnTable()
local dummy = { 3.0, 19.0, 0.9 }
local resultExpected = '3.0 19.0 0.9'
local onFailureMsg = tostring(dummy) .. " is different than " .. tostring(resultExpected)
local f = ConvertTableToStr(dummy)
if f == '' then
luaunit.fail("The function returned an empty string. Wich is one of thoose cases.")
end
luaunit.assertEquals(f, resultExpected, onFailureMsg)
end
--[[
**********************************************
RandomizePrefabProperty()
**********************************************
]]--
function test_RandomizePrefabProperty_ShouldReturnStrType()
local dummyProperty = 'texture'
local resultExpected = 'string'
local onFailureMsg = "Type doesn't match."
local f = RandomizePrefabProperty(dummyProperty)
luaunit.assertEquals(type(f), resultExpected, onFailureMsg)
dummyProperty = 'blendtexture'
luaunit.assertEquals(type(f), resultExpected, onFailureMsg)
end
--[[
**********************************************
CalculateAxisAccordingWorldAndObject()
**********************************************
]]--
-- Check: Return Type
function test_CalcSpawnPosOffset_ShouldReturnTableType()
local time = os.time()
local dummyobjectPos = { 3.0, 10.0, 34.0 }
local dummyWordLength = {
CONSTANTS.WORLD.SIZE.WIDTH - 100,
CONSTANTS.WORLD.SIZE.HEIGHT - 40,
CONSTANTS.WORLD.SIZE.DEPTH - 100
}
print("\n")
print("Init Function output:")
print("> test_CalcSpawnPosWithOffset_ShouldReturnTableType")
print("-----------------------")
local f = CalcSpawnPosWithOffset(dummyobjectPos, dummyWordLength, 1.5)
print("-----------------------")
print("End Function output:")
print("\n")
local resultExpected = 'table'
local onFailureMsg = "Type doesn't match."
luaunit.assertEquals(type(f),resultExpected, onFailureMsg)
end
function test_CalcSpawnPosWithOffset_WhenSomeValueIsNegative_ShouldReturnTable()
local time = os.time()
-- if you setup some table value with negative, it always be
-- a negative in result of function
local dummyobjectPos = { 201.0, -10.0, 35.0 }
local dummyWordLength = {
CONSTANTS.WORLD.SIZE.WIDTH - 100,
CONSTANTS.WORLD.SIZE.HEIGHT - 40,
CONSTANTS.WORLD.SIZE.DEPTH - 100
}
print("\n")
print("Init Function output:")
print("> test_CalcSpawnPosWithOffset_WhenSomeValueIsNegative_ShouldReturnTable")
print("-----------------------")
local f = CalcSpawnPosWithOffset(dummyobjectPos, dummyWordLength, 1.5)
print("-----------------------")
print("End Function output:")
print("\n")
--local resultExpected = 'table'
--local onFailureMsg = "The value is not negative."
--luaunit.assertEquals(type(f), resultExpected, onFailureMsg)
end
os.exit(luaunit.LuaUnit.run())
else
os.execute("echo ::::::::: TESTS ENV DISABLED ::::::::::")
os.execute("echo You need to set MOD.UNIT_TESTS=true in 'config.lua' file.")
end