
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Iteration
Following the Grammar
% $Id: DeleteAllTest.oz,v 1.5 2008/02/11 02:01:14 leavens Exp leavens $ \insert ’TestingNoStop.oz’ \insert ’DeleteAll.oz’ {StartTesting ’DeleteAll’} {Test {DeleteAll nil 3} ’==’ nil} {Test {DeleteAll [1 1 2 3 2 1 2 3 2 1] 1} ’==’ [2 3 2 2 3 2]} {Test {DeleteAll [1 2 3 2 1 2 3 2 1] 1} ’==’ [2 3 2 2 3 2]} {Test {DeleteAll [1 1 2 3 2 1 2 3 2 1] 4} ’==’ [1 1 2 3 2 1 2 3 2 1]} {Test {DeleteAll [99 56 3] 3} ’==’ [99 56]}
% $Id: DeleteSecondTest.oz,v 1.5 2008/02/11 02:02:15 leavens Exp leavens $ \insert ’TestingNoStop.oz’ \insert ’DeleteSecond.oz’ {StartTesting ’DeleteSecond’} {Test {DeleteSecond nil 3} ’==’ nil} {Test {DeleteSecond [1 2 3 2 1 2 3 2 1] 1} ’==’ [1 2 3 2 2 3 2 1]} {Test {DeleteSecond [1 2 3 2 1 2 3 2 1] 4} ’==’ [1 2 3 2 1 2 3 2 1]} {Test {DeleteSecond [1 2 3] 3} ’==’ [1 2 3]} {Test {DeleteSecond [3 1 2 3] 3} ’==’ [3 1 2]}
% $Id: SetOpsTest.oz,v 1.6 2008/03/03 15:33:19 leavens Exp leavens $ \insert ’SetOps.oz’ \insert ’TestingNoStop.oz’
{StartTesting ’SetOps’} {Assert {Equal {AsSet nil} {EmptySet}}} {Assert {Equal {AsSet [1 2 3]} {AsSet [3 1 2]}}} {Assert {Not {Equal {AsSet [1 2 3]} {AsSet [1 2]}}}} {Assert {Not {Equal {AsSet [c b]} {AsSet [a b c]}}}} {StartTesting ’Add’} {Assert {Equal {Add {EmptySet} 1} {AsSet [1]}}} {Assert {Equal {Add {AsSet [2 3]} 1} {AsSet [1 2 3]}}} {Assert {Equal {Add {AsSet [2 3 1]} 1} {AsSet [2 1 3]}}} {StartTesting ’Remove’} {Assert {Equal {Remove {EmptySet} 7} {EmptySet}}} {Assert {Equal {Remove {AsSet [2 3 1]} 1} {AsSet [3 2]}}} {Assert {Equal {Remove {AsSet [2 3 1 5 7 4]} 5} {AsSet [3 2 1 7 4]}}} {Assert {Equal {Remove {AsSet [2 3 4 8]} 1} {AsSet [2 3 4 8]}}} {StartTesting ’Union’} {Assert {Equal {Union {EmptySet} {AsSet [d e]}} {AsSet [d e]}}} {Assert {Equal {Union {AsSet [a b c]} {EmptySet}} {AsSet [a b c]}}} {Assert {Equal {Union {AsSet [a b c]} {AsSet [d e]}} {AsSet [a b c d e]}}} {Assert {Equal {Union {AsSet [e a b c]} {AsSet [c d e a]}} {AsSet [a b c d e]}}} {StartTesting ’Minus’} {Assert {Equal {Minus {EmptySet} {AsSet [d e]}} {EmptySet}}} {Assert {Equal {Minus {AsSet [d e]} {EmptySet}} {AsSet [d e]}}} {Assert {Equal {Minus {AsSet [a b c]} {AsSet [d e]}} {AsSet [a b c]}}} {Assert {Equal {Minus {AsSet [e a b c]} {AsSet [c d a e]}} {AsSet [b]}}} {Assert {Equal {Minus {AsSet [e a b c]} {AsSet [c e d a f]}} {AsSet [b]}}} {Assert {Equal {Minus {AsSet [a b]} {AsSet [b a]}} {AsSet nil}}} {StartTesting ’Intersect’} {Assert {Equal {Intersect {EmptySet} {AsSet [d e]}} {EmptySet}}} {Assert {Equal {Intersect {AsSet [a b c]} {AsSet [d e]}} {EmptySet}}} {Assert {Equal {Intersect {AsSet [e a b c]} {AsSet [c d a e]}} {AsSet [a e c]}}} {Assert {Equal {Intersect {AsSet [e a b c]} {AsSet [c e d a f b]}} {AsSet [c b a e]}}} {Assert {Equal {Intersect {AsSet [a b]} {AsSet [b a]}} {AsSet [a b]}}} {StartTesting ’UnionList’} {Assert {Equal {UnionList nil} {EmptySet}}} {Assert {Equal {UnionList [{AsSet [a b c]} {AsSet nil} {AsSet [d e]}]} {AsSet [a b c d e]}}} {Assert {Equal {UnionList [{AsSet [a]} {AsSet [b c]} {EmptySet} {AsSet [d e]} {AsSet [f g h i j]} {AsSet [k l m a b e]}]} {AsSet [a b c d e f g h i j k l m]}}}
% $Id: ShrinkToTest.oz,v 1.2 2008/02/11 02:18:01 leavens Exp leavens $ \insert ’ShrinkTo.oz’ \insert ’TestingNoStop.oz’ {Test {ShrinkTo vertical(nil) 10 39} ’==’ vertical(nil)} {Test {ShrinkTo horizontal(nil) 10 39} ’==’ horizontal(nil)} {Test {ShrinkTo window(name: simpsons width: 30 height: 40) 10 39} ’==’ window(name: simpsons width: 10 height: 39)} {Test {ShrinkTo window(name: simpsons width: 30 height: 11) 10 39} ’==’ window(name: simpsons width: 10 height: 11)} {Test {ShrinkTo window(name: familyGuy width: 30 height: 11) 80 39} ’==’ window(name: familyGuy width: 30 height: 11)} {Test {ShrinkTo window(name: familyGuy width: 30 height: 11) 80 5} ’==’ window(name: familyGuy width: 30 height: 5)} {Test {ShrinkTo horizontal([window(name: familyGuy width: 30 height: 15) window(name: futurama width: 89 height: 55)]) 20 30} ’==’ horizontal([window(name: familyGuy width: 20 height: 15) window(name: futurama width: 20 height: 30)])} {Test {ShrinkTo vertical( [vertical([window(name: simpsons width: 30 height: 40)]) horizontal([horizontal([window(name: news width: 5 height: 5)])]) horizontal([window(name: familyGuy width: 30 height: 15) window(name: futurama width: 89 height: 55)])]) 20 30} ’==’ vertical( [vertical([window(name: simpsons width: 20 height: 30)]) horizontal([horizontal([window(name: news width: 5 height: 5)])]) horizontal([window(name: familyGuy width: 20 height: 15) window(name: futurama width: 20 height: 30)])])}
% $Id: BEvalTest.oz,v 1.2 2008/02/11 02:26:42 leavens Exp $ \insert ’BEval.oz’ \insert ’TestingNoStop.oz’ declare fun {StdEnv A} case A of p then 1 [] q then 2 [] r then 4020 [] x then 76 [] y then 0 else raise stdEnvIsUndefinedOn(A) end end end
{StartTesting ’BEval’} {Assert {BEval comp(equals(q q)) StdEnv} == true } {Assert {BEval comp(notequals(q q)) StdEnv} == false } {Assert {BEval comp(equals(q r)) StdEnv} == false } {Assert {BEval comp(notequals(p q)) StdEnv} == true } {Assert {BEval andExp(comp(notequals(p q)) comp(equals(x x))) StdEnv} == true } {Assert {BEval andExp(comp(notequals(p q)) comp(notequals(x x))) StdEnv} == false } {Assert {BEval andExp(notExp(comp(equals(p p))) comp(equals(x x))) StdEnv} == false } {Assert {BEval notExp(andExp(notExp(comp(equals(p p))) comp(equals(x x)))) StdEnv} == true } {Assert {BEval orExp(notExp(andExp(notExp(comp(equals(p p))) comp(equals(x x)))) orExp(comp(equals(p q)) comp(equals(x x)))) StdEnv} == true } {Assert {BEval orExp(andExp(notExp(comp(equals(p p))) comp(equals(x x))) orExp(comp(equals(p q)) comp(equals(x y)))) StdEnv} == false }
% $Id: AllIdsTest.oz,v 1.1 2007/09/24 22:14:44 leavens Exp leavens $ \insert ’AllIds.oz’ \insert ’TestingNoStop.oz’ {StartTesting ’AllIds’} {Assert {Equal {AllIds expStmt(varExp(q))} {AsSet [q]}}} {Assert {Equal {AllIds expStmt(varExp(r))} {AsSet [r]}}} {Assert {Equal {AllIds assignStmt(a varExp(b))} {AsSet [a b]}}} {Assert {Equal {AllIds ifStmt(equalsExp(varExp(id) numExp(0)) assignStmt(id varExp(b)))} {AsSet [id b]}}} {Assert {Equal {AllIds expStmt(beginExp(nil varExp(a)))} {AsSet [a]}}} {Assert {Equal {AllIds expStmt(beginExp([ifStmt(equalsExp(varExp(a) numExp(0)) assignStmt(v varExp(q))) assignStmt(v2 varExp(w))] beginExp([expStmt(varExp(r))] varExp(a))))} {AsSet [a v q v2 w r]}}}
% $Id: SubstIdentifierTest.oz,v 1.3 2008/02/11 02:48:48 leavens Exp leavens $ \insert ’SubstIdentifier.oz’ \insert ’TestingNoStop.oz’ {StartTesting ’SubstIdentifier’} {Assert {SubstIdentifier expStmt(varExp(q)) p q} == expStmt(varExp(p))} {Assert {SubstIdentifier expStmt(varExp(r)) p q} == expStmt(varExp(r))} {Assert {SubstIdentifier assignStmt(a varExp(a)) n a} == assignStmt(n varExp(n))} {Assert {SubstIdentifier ifStmt(equalsExp(varExp(id) numExp(0)) assignStmt(id varExp(b))) var id} == ifStmt(equalsExp(varExp(var) numExp(0)) assignStmt(var varExp(b)))} {Assert {SubstIdentifier expStmt(beginExp(nil varExp(a))) n a} == expStmt(beginExp(nil varExp(n)))} {Assert {SubstIdentifier expStmt(beginExp([ifStmt(equalsExp(varExp(a) numExp(0)) assignStmt(a varExp(b))) assignStmt(a varExp(a)) ] beginExp(nil varExp(a)))) n a} == expStmt(beginExp([ifStmt(equalsExp(varExp(n) numExp(0)) assignStmt(n varExp(b))) assignStmt(n varExp(n)) ] beginExp(nil varExp(n))))}
% $Id: AssociatedTest.oz,v 1.7 2008/02/11 02:52:03 leavens Exp leavens $ \insert ’Associated.oz’ \insert ’TestingNoStop.oz’
declare proc {AssociatedTest Associated} {Test {Associated nil 3} ’==’ nil} {Test {Associated [(3#4) (5#7) (3#6) (9#3)] 3} ’==’ [4 6]} {Test {Associated [(1#a) (3#c) (2#b) (4#d)] 2} ’==’ [b]} {Test {Associated [(1#a) (3#c) (2#b) (4#d)] 0} ’==’ nil} end
{StartTesting ’Part (a)’} {AssociatedTest AssociatedPartA} {StartTesting ’Part (b)’} {AssociatedTest AssociatedPartB} {StartTesting ’Part (c)’} {AssociatedTest AssociatedPartC}
% $Id: BorrowedTest.oz,v 1.5 2008/02/11 03:00:09 leavens Exp leavens $ \insert ’Borrowed.oz’ \insert ’TestingNoStop.oz’ declare ExampleBase = [ (’Alice’ # ’Tintin’) (’Anna’ # ’Little Women’) (’Alice’ # ’Asterix’) (’Rory’ # ’Tintin’) ]
{StartTesting ’Borrowers, part (a)’} {Test {Borrowers ExampleBase ’Tintin’} ’==’ [’Alice’ ’Rory’]} {Test {Borrowers ExampleBase ’Little Women’} ’==’ [’Anna’]} {Test {Borrowers ExampleBase ’Asterix’} ’==’ [’Alice’]} {Test {Borrowers ExampleBase ’The Wizard of Oz’} ’==’ nil}
{StartTesting ’Borrowed, part (b)’} {Test {Borrowed ExampleBase ’Tintin’} ’==’ true } {Test {Borrowed ExampleBase ’Little Women’} ’==’ true } {Test {Borrowed ExampleBase ’Asterix’} ’==’ true } {Test {Borrowed ExampleBase ’The Wizard of Oz’} ’==’ false }
{StartTesting ’NumBorrowed, part (c)’} {Test {NumBorrowed ExampleBase ’Alice’} ’==’ 2} {Test {NumBorrowed ExampleBase ’Anna’} ’==’ 1} {Test {NumBorrowed ExampleBase ’Rory’} ’==’ 1} {Test {NumBorrowed ExampleBase ’Ben’} ’==’ 0}
% $Id: ComposeTest.oz,v 1.7 2008/02/11 03:05:44 leavens Exp leavens $ \insert ’Compose.oz’ \insert ’TestingNoStop.oz’ {StartTesting ’Compose’} {Test {{Compose nil} [1 2 3]} ’==’ [1 2 3]} local fun {Tail Ls} _|Rest = Ls in Rest end in {Test {{Compose [Tail]} [1 2 3 4 5]} ’==’ [2 3 4 5]} {Test {{Compose [Tail Tail Tail]} [1 2 3 4 5]} ’==’ [4 5]} end {Test {{Compose [ fun {$ X} X + 1 end fun {$ X} X + 2 end ]} 4} ’==’ 7} {Test {{Compose [ fun {$ X} 3|X end fun {$ Y} 4|Y end ]} nil} ’==’ 3|(4|nil)}
% $Id: CommaSeparateTest.oz,v 1.4 2008/02/11 03:59:11 leavens Exp leavens $ \insert ’CommaSeparate.oz’ \insert ’TestingNoStop.oz’ \insert ’CommaSeparateBodyTest.oz’
% $Id: CommaSeparateBodyTest.oz,v 1.1 2008/02/11 03:59:17 leavens Exp leavens $ {StartTesting ’CommaSeparate’} {Test {CommaSeparate nil} ’==’ ""} {Test {CommaSeparate ["a" "b"]} ’==’ "a, b"} {Test {CommaSeparate ["Monday" "Tuesday" "Wednesday" "Thursday"]} ’==’ "Monday, Tuesday, Wednesday, Thursday"}
% $Id: OnSeparateLinesTest.oz,v 1.4 2008/02/11 04:01:15 leavens Exp leavens $ \insert ’OnSeparateLines.oz’ \insert ’TestingNoStop.oz’ \insert ’OnSeparateLinesBodyTest.oz’
% $Id: OnSeparateLinesBodyTest.oz,v 1.1 2008/02/11 04:01:20 leavens Exp leavens $ {StartTesting ’OnSeparateLines’} {Test {OnSeparateLines nil} ’==’ ""} {Test {OnSeparateLines ["a" "b"]} ’==’ "a\nb"} {Test {OnSeparateLines ["Monday" "Tuesday" "Wednesday" "Thursday"]} ’==’ "Monday\nTuesday\nWednesday\nThursday"}
% $Id: DoubleAllTest.oz,v 1.4 2008/02/11 04:12:19 leavens Exp leavens $ \insert ’DoubleAll.oz’ \insert ’TestingNoStop.oz’ \insert ’DoubleAllBodyTest.oz’
% $Id: DoubleAllBodyTest.oz,v 1.1 2008/02/11 04:12:24 leavens Exp leavens $ {StartTesting ’DoubleAll’} {Test {DoubleAll nil} ’==’ nil} {Test {DoubleAll [1 2 3]} ’==’ [2 4 6]} {Test {DoubleAll [3 6 2 5 4 1]} ’==’ [6 12 4 10 8 2]}
% $Id: SumTreeTest.oz,v 1.5 2008/02/11 04:22:17 leavens Exp leavens $ \insert ’SumTree.oz’ \insert ’TestingNoStop.oz’ \insert ’SumTreeBodyTest.oz’
% $Id: SumTreeBodyTest.oz,v 1.1 2008/02/11 04:22:37 leavens Exp leavens $ {StartTesting ’SumTree’} {Test {SumTree node(item:4 subtrees:nil)} ’==’ 4} {Test {SumTree node(item: subtrees:[node(item:4 subtrees:nil) node(item:7 subtrees:nil)])} ’==’ 14} {Test {SumTree node(item: subtrees:[node(item: subtrees:[node(item:4 subtrees:nil) node(item:7 subtrees:nil)]) node(item: subtrees:[node(item:20 subtrees: nil) node(item:30 subtrees: nil) node(item:40 subtrees: nil)] )])} ’==’ 124}
% $Id: MapTreeTest.oz,v 1.4 2008/02/11 04:32:14 leavens Exp leavens $ \insert ’MapTree.oz’ \insert ’TestingNoStop.oz’ \insert ’MapTreeBodyTest.oz’
% $Id: MapTreeBodyTest.oz,v 1.1 2008/02/11 04:32:00 leavens Exp leavens $ {StartTesting ’MapTree’} local fun {Add1 X} X+1 end fun {Add3 X} X+3 end in {Test {MapTree node(item:4 subtrees:nil) Add1} ’==’ node(item:5 subtrees:nil)} {Test {MapTree node(item: subtrees:[node(item:4 subtrees:nil) node(item:7 subtrees:nil)]) Add3} ’==’ node(item: subtrees:[node(item:7 subtrees:nil) node(item:10 subtrees:nil)])} {Test {MapTree node(item: subtrees:[node(item: subtrees:[node(item:4 subtrees:nil) node(item:7 subtrees:nil)]) node(item: subtrees:[node(item:20 subtrees: nil) node(item:30 subtrees: nil) node(item:40 subtrees: nil)] )]) Add3} ’==’ node(item: subtrees:[node(item: subtrees:[node(item:7 subtrees:nil) node(item:10 subtrees:nil)]) node(item: subtrees:[node(item:23 subtrees: nil) node(item:33 subtrees: nil) node(item:43 subtrees: nil)] )])} end