Skip to content

Commit

Permalink
Replace torch.Tester with totem.Tester + extra stuff.
Browse files Browse the repository at this point in the history
This should bring a lot of benefit to code that uses torch.Tester (totem will
eventually become deprecated). Note that torch.Tester and totem.Tester once
shared the same code - this change brings it full circle.

At a glance, extra functionality includes:
- A general equality checker that accepts many different objects.
- Deep table comparison with precision checking.
- Stricter argument checking in using the test functions.
- Better output.
- torch.Storage comparison.
- Extra features for fine-grained control of testing.
  • Loading branch information
davidsaxton committed Feb 25, 2016
1 parent 3bbb49f commit d8ff64c
Show file tree
Hide file tree
Showing 12 changed files with 1,775 additions and 292 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ script:
- ${TESTLUA} -ltorch -e "t=torch.test(); if t.errors[1] then os.exit(1) end"
- cd test
- ${TESTLUA} test_writeObject.lua
- ${TESTLUA} test_Tester.lua
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/lib/luaT")
LINK_DIRECTORIES("${LUA_LIBDIR}")

SET(src DiskFile.c File.c MemoryFile.c PipeFile.c Storage.c Tensor.c Timer.c utils.c init.c TensorOperator.c TensorMath.c random.c Generator.c)
SET(luasrc init.lua File.lua Tensor.lua CmdLine.lua FFI.lua Tester.lua test/test.lua)
SET(luasrc init.lua File.lua Tensor.lua CmdLine.lua FFI.lua Tester.lua TestSuite.lua test/test.lua)

# Necessary do generate wrapper
ADD_TORCH_WRAP(tensormathwrap TensorMath.lua)
Expand Down
30 changes: 30 additions & 0 deletions TestSuite.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function torch.TestSuite()
local obj = {
__tests = {},
__isTestSuite = true
}

local metatable = {}

function metatable:__index(key)
return self.__tests[key]
end

function metatable:__newindex(key, value)
if self.__tests[key] ~= nil then
error("Test " .. tostring(key) .. " is already defined.")
end
if type(value) ~= "function" then
if type(value) == "table" then
error("Nested tables of tests are not supported")
else
error("Only functions are supported as members of a TestSuite")
end
end
self.__tests[key] = value
end

setmetatable(obj, metatable)

return obj
end
Loading

0 comments on commit d8ff64c

Please sign in to comment.