/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * eine Test Programm fuer die Klasse SExpr */ //-------------------- public class Test { //-------------------- // count failed tests static int failed = 0; //-------------------- static void test( Object result, Object expected, String testCase ) { if ( ! result.equals(expected) ) { ++ failed; System.out.println ("Test Case " + testCase + " failed\n" + "result : " + result.toString() + "\n" + "expected : " + expected.toString() ); } } //-------------------- static void test( SExpr result, SExpr expected, String testCase ) { if ( result.isEqual(expected) == SExpr.nil ) { test((Object)result, (Object)expected, testCase); } } //-------------------- public static void main(String[] argv) { test(SExpr.nil.toString(), "()", "toString 1.1"); test(SExpr.t.toString(), "#t", "toString 1.2"); test((new Symbol("abc")).toString(), "abc", "toString 1.3"); test((new Number((long)123)).toString(), "123", "toString 1.4"); test(SExpr.t.cons(SExpr.t).toString(), "( #t . #t )", "toString 1.5"); //-------------------- test(SExpr.t.isEqual(SExpr.t), SExpr.t, "isEqual 1.1"); test(SExpr.nil.isEqual(SExpr.nil), SExpr.t, "isEqual 1.2"); test(SExpr.t.isEqual(SExpr.nil), SExpr.nil, "isEqual 1.3"); test(SExpr.nil.isEqual(SExpr.t), SExpr.nil, "isEqual 1.4"); test((new Symbol("abc")).isEqual(new Symbol("abc")), SExpr.t, "isEqual 1.5"); test((new Symbol("abc")).isEqual(new Symbol("xyz")), SExpr.nil, "isEqual 1.6"); { SExpr t = SExpr.t; SExpr nil = SExpr.nil; SExpr s1 = new Symbol("abc"); SExpr s2 = new Symbol("xyz"); SExpr n1 = new Number(0); SExpr n2 = new Number(1); SExpr l1 = s1.cons(SExpr.nil); SExpr p1 = s2.cons(s1); test(s1.isEqual(s1),SExpr.t,"isEqual 1.7.1"); test(n1.isEqual(n1),SExpr.t,"isEqual 1.7.2"); test(l1.isEqual(l1),SExpr.t,"isEqual 1.7.3"); test(s1.isEqual(s2),SExpr.nil,"isEqual 1.8.1"); test(n1.isEqual(n2),SExpr.nil,"isEqual 1.8.2"); test(l1.isEqual(p1),SExpr.nil,"isEqual 1.8.3"); test(s1.isEqual(n1),SExpr.nil,"isEqual 1.9.1"); test(s1.isEqual(l1),SExpr.nil,"isEqual 1.9.2"); test(n1.isEqual(l1),SExpr.nil,"isEqual 1.9.3"); test( t.isList(),SExpr.nil,"isList 1.1"); test(nil.isList(),SExpr.t ,"isList 1.2"); test( n1.isList(),SExpr.nil,"isList 1.3"); test( s1.isList(),SExpr.nil,"isList 1.4"); test( l1.isList(),SExpr.t ,"isList 1.5"); test( p1.isList(),SExpr.nil,"isList 1.6"); test( t.isPair(),SExpr.nil,"isPair 1.1"); test(nil.isPair(),SExpr.nil,"isPair 1.2"); test( n1.isPair(),SExpr.nil,"isPair 1.3"); test( s1.isPair(),SExpr.nil,"isPair 1.4"); test( l1.isPair(),SExpr.t ,"isPair 1.5"); test( p1.isPair(),SExpr.t ,"isPair 1.6"); test( t.isAtom(),SExpr.t ,"isAtom 1.1"); test(nil.isAtom(),SExpr.t ,"isAtom 1.2"); test( n1.isAtom(),SExpr.t ,"isAtom 1.3"); test( s1.isAtom(),SExpr.t ,"isAtom 1.4"); test( l1.isAtom(),SExpr.nil,"isAtom 1.5"); test( t.isNull(),SExpr.nil,"isNull 1.1"); test(nil.isNull(),SExpr.t ,"isNull 1.2"); test( n1.isNull(),SExpr.nil,"isNull 1.3"); test( s1.isNull(),SExpr.nil,"isNull 1.4"); test( l1.isNull(),SExpr.nil,"isNull 1.5"); test( t.isNull(),SExpr.t, "wrong test case 1.42"); } //-------------------- // statistics System.out.println ( (failed == 0) ? "all tests passed" : (failed + " Test(s) failed") ); } }