aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/lua-torch/torch7/TestSuite.lua
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/lua-torch/torch7/TestSuite.lua')
-rw-r--r--contrib/lua-torch/torch7/TestSuite.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/contrib/lua-torch/torch7/TestSuite.lua b/contrib/lua-torch/torch7/TestSuite.lua
new file mode 100644
index 000000000..630c2c948
--- /dev/null
+++ b/contrib/lua-torch/torch7/TestSuite.lua
@@ -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