# HG changeset patch # User Matthew Wild # Date 1288086236 -3600 # Node ID 3e148db7f933bd72551e8c298f9aae9803d1a1e1 # Parent d02c7932cbf26a7eca79b012fddbfb0855897965 Add tests/ to the repo diff -r d02c7932cbf2 -r 3e148db7f933 tests/fail/demo_account.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/fail/demo_account.lua Tue Oct 26 10:43:56 2010 +0100 @@ -0,0 +1,38 @@ +-- account.lua +-- from PiL 1, Chapter 16 + +Account = {balance = 0} + +function Account:new (o, name) + o = o or {name=name} + setmetatable(o, self) + self.__index = self + return o +end + +function Account:deposit (v) + self.balance = self.balance + v +end + +function Account:withdraw (v) + if v > self.balance then error("insufficient funds on account "..self.name) end + self.balance = self.balance - v +end + +function Account:show (title) + print(title or "", self.name, self.balance) +end + +a = Account:new(nil,"demo") +a:show("after creation") +a:deposit(1000.00) +a:show("after deposit") +a:withdraw(100.00) +a:show("after withdraw") + +-- this would raise an error +--[[ +b = Account:new(nil,"DEMO") +b:withdraw(100.00) +--]] + diff -r d02c7932cbf2 -r 3e148db7f933 tests/fail/demo_bisect.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/fail/demo_bisect.lua Tue Oct 26 10:43:56 2010 +0100 @@ -0,0 +1,29 @@ +-- bisect.lua +-- bisection method for solving non-linear equations + +delta=1e-6 -- tolerance + +function bisect(f,a,b,fa,fb) + local c=(a+b)/2 + io.write(n," c=",c," a=",a," b=",b,"\n") + if c==a or c==b or math.abs(a-b)/dev/null || failtest "$script"; + test_count=$(($test_count+1)) +done + +for script in tests/fail/*.lua; do + luac "$script" && node lvm.js >/dev/null && failtest "$script"; + test_count=$(($test_count+1)) +done + +echo $(($test_count-$failed_count))"/$test_count TESTS PASSED"; +if ! [ "$failed" == "" ]; then + echo "$failed_count TESTS FAILED:"; + echo "$failed"; + exit 1; +fi +exit 0;