Expanded the test suite.
This commit is contained in:
parent
6b1341f83b
commit
56ba492a94
8
test.sh
Executable file
8
test.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
cd ./test/
|
||||
|
||||
for file in *.lua; do
|
||||
lua "$file"
|
||||
done
|
||||
|
@ -6,7 +6,7 @@ dofile("../utils/test.lua")
|
||||
dofile("../utils/blockedcache.lua")
|
||||
|
||||
|
||||
function test_basic()
|
||||
local function test_basic()
|
||||
local cache = BlockedCache:new()
|
||||
|
||||
cache:put(0, 0, "a")
|
||||
@ -15,7 +15,7 @@ function test_basic()
|
||||
test.equals("a", cache:get(0, 0))
|
||||
end
|
||||
|
||||
function test_auto_compacting()
|
||||
local function test_auto_compacting()
|
||||
local cache = BlockedCache:new(5, true)
|
||||
|
||||
cache:put(0, 0, "a")
|
||||
@ -48,6 +48,7 @@ function test_auto_compacting()
|
||||
end
|
||||
|
||||
|
||||
test_basic()
|
||||
test_auto_compacting()
|
||||
test.start("BlockedCache")
|
||||
test.run("auto_compacting", test_auto_compacting)
|
||||
test.run("basic", test_basic)
|
||||
|
||||
|
@ -6,14 +6,14 @@ dofile("../utils/test.lua")
|
||||
dofile("../utils/mathutil.lua")
|
||||
|
||||
|
||||
function test_clamp()
|
||||
local function test_clamp()
|
||||
test.equals(0, mathutil.clamp(0, 0, 0))
|
||||
|
||||
test.equals(0, mathutil.clamp(-10, 0, 20))
|
||||
test.equals(20, mathutil.clamp(30, 0, 20))
|
||||
end
|
||||
|
||||
function test_round()
|
||||
local function test_round()
|
||||
test.equals(0, mathutil.round(0))
|
||||
|
||||
test.equals(0, mathutil.round(0.3))
|
||||
@ -27,6 +27,7 @@ function test_round()
|
||||
test.equals(1.234, mathutil.round(1.2344756, 3))
|
||||
end
|
||||
|
||||
test_clamp()
|
||||
test_round()
|
||||
test.start("mathutil")
|
||||
test.run("clamp", test_clamp)
|
||||
test.run("round", test_round)
|
||||
|
||||
|
@ -25,7 +25,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
--]]
|
||||
|
||||
|
||||
--- A simple utility for testing values.
|
||||
--- A simple utility for testing values and running unit tests.
|
||||
test = {}
|
||||
|
||||
|
||||
@ -54,3 +54,31 @@ function test.equals(expected, actual, message)
|
||||
end
|
||||
end
|
||||
|
||||
--- Runs the given method and prints a formatted information including the name.
|
||||
--
|
||||
-- @param name The name of the method that is being run.
|
||||
-- @param test_method The method to run.
|
||||
function test.run(name, test_method)
|
||||
io.write(string.rep(" ", 20 - string.len(name)))
|
||||
io.write(name)
|
||||
io.write(" ... ")
|
||||
|
||||
local status, err = pcall(test_method)
|
||||
|
||||
if status then
|
||||
print("Passed")
|
||||
else
|
||||
local indentation = string.rep(" ", 28)
|
||||
print("Failed: " .. string.gsub(err, "\n", "\n" .. indentation))
|
||||
end
|
||||
end
|
||||
|
||||
--- Prints the given name as header.
|
||||
--
|
||||
-- @param name The name of the header.
|
||||
function test.start(name)
|
||||
print("\n")
|
||||
print(string.rep(" ", 20 - string.len(name)) .. name)
|
||||
print(string.rep("-", 80))
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user