# HG changeset patch # User Paul Boddie # Date 1106438500 -3600 # Node ID 1dc70ce136802cb6c03db270db5217f48f003c06 # Parent 904c1223e3aa3503a3f7854318a6568c59dfa244 Added more tests. diff -r 904c1223e3aa -r 1dc70ce13680 tests/AbstractClassTest.java --- a/tests/AbstractClassTest.java Sun Jan 23 01:01:34 2005 +0100 +++ b/tests/AbstractClassTest.java Sun Jan 23 01:01:40 2005 +0100 @@ -1,5 +1,13 @@ public abstract class AbstractClassTest { public static ConcreteClassTest member = new ConcreteClassTest(); + + public static void main(String[] args) { + if (AbstractClassTest.member != null) { + System.out.println("AbstractClassTest.member correct: " + AbstractClassTest.member); + } else { + System.err.println("AbstractClassTest.member failed!"); + } + } } // vim: tabstop=4 expandtab shiftwidth=4 diff -r 904c1223e3aa -r 1dc70ce13680 tests/DispatchTest.java --- a/tests/DispatchTest.java Sun Jan 23 01:01:34 2005 +0100 +++ b/tests/DispatchTest.java Sun Jan 23 01:01:40 2005 +0100 @@ -45,6 +45,52 @@ public int testTest(DispatchInterface obj) { return test(obj); } + + public static void main(String[] args) { + DispatchTest test = new DispatchTest(); + DispatchClass1 dc1 = new DispatchClass1(); + DispatchClass2 dc2 = new DispatchClass2(); + + if (test.a == 1 && test.b == 2) { + System.out.println("test.a, test.b correct: " + test.a + ", " + test.b); + } else { + System.err.println("test.a, test.b failed!"); + } + test.set(5); + if (test.a == 5 && test.b == 2) { + System.out.println("test.a, test.b correct: " + test.a + ", " + test.b); + } else { + System.err.println("test.a, test.b failed!"); + } + test.set(7.0f); + if (test.a == 5 && test.b == 7.0f) { + System.out.println("test.a, test.b correct: " + test.a + ", " + test.b); + } else { + System.err.println("test.a, test.b failed!"); + } + if (test.test(dc1) == 11) { + System.out.println("test.test(dc1) correct: " + test.test(dc1)); + } else { + System.err.println("test.test(dc1) failed!"); + } + if (test.test(dc2) == 2) { + System.out.println("test.test(dc2) correct: " + test.test(dc2)); + } else { + System.err.println("test.test(dc2) failed!"); + } + // Yes, one might think this could be 11, but the parameter becomes + // "more vague" when passed to testTest. + if (test.testTest(dc1) == 1) { + System.out.println("test.testTest(dc1) correct: " + test.testTest(dc1)); + } else { + System.err.println("test.testTest(dc1) failed!"); + } + if (test.testTest(dc2) == 2) { + System.out.println("test.testTest(dc2) correct: " + test.testTest(dc2)); + } else { + System.err.println("test.testTest(dc2) failed!"); + } + } } interface DispatchInterface { @@ -62,3 +108,5 @@ return 2; } } + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 904c1223e3aa -r 1dc70ce13680 tests/StaticTest.java --- a/tests/StaticTest.java Sun Jan 23 01:01:34 2005 +0100 +++ b/tests/StaticTest.java Sun Jan 23 01:01:40 2005 +0100 @@ -3,6 +3,24 @@ public static StaticTestClass staticMember = StaticTestClass.newInstance(); public static StaticTestClass staticMember2 = StaticTestClass.newInstance(123); public static int staticMember3 = StaticTestClass.getNumber(); + + public static void main(String[] args) { + if (StaticTest.staticMember != null && StaticTest.staticMember.x == 321) { + System.out.println("StaticTest.staticMember.x correct: " + StaticTest.staticMember.x); + } else { + System.out.println("StaticTest.staticMember.x failed!"); + } + if (StaticTest.staticMember2 != null && StaticTest.staticMember2.x == 123) { + System.out.println("StaticTest.staticMember2.x correct: " + StaticTest.staticMember2.x); + } else { + System.out.println("StaticTest.staticMember2.x failed!"); + } + if (StaticTest.staticMember3 == 456) { + System.out.println("StaticTest.staticMember3 correct: " + StaticTest.staticMember3); + } else { + System.out.println("StaticTest.staticMember3 failed!"); + } + } } class StaticTestClass { @@ -28,3 +46,5 @@ return 456; } } + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 904c1223e3aa -r 1dc70ce13680 tests/StringBufferTest.java --- a/tests/StringBufferTest.java Sun Jan 23 01:01:34 2005 +0100 +++ b/tests/StringBufferTest.java Sun Jan 23 01:01:40 2005 +0100 @@ -2,9 +2,31 @@ StringBuffer sb1; StringBuffer sb2; String s; + public StringBufferTest(String a, String b) { sb1 = new StringBuffer(a); sb2 = new StringBuffer(b); s = a + b; } + + public static void main(String[] args) { + StringBufferTest test = new StringBufferTest("Hello ", "world"); + if (test.sb1.toString().equals("Hello ")) { + System.out.println("test.sb1.toString() correct: " + test.sb1.toString()); + } else { + System.err.println("test.sb1.toString() failed!"); + } + if (test.sb2.toString().equals("world")) { + System.out.println("test.sb2.toString() correct: " + test.sb2.toString()); + } else { + System.err.println("test.sb2.toString() failed!"); + } + if (test.s.equals("Hello world")) { + System.out.println("test.s correct: " + test.s); + } else { + System.err.println("test.s failed!"); + } + } } + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 904c1223e3aa -r 1dc70ce13680 tests/StringTest.java --- a/tests/StringTest.java Sun Jan 23 01:01:34 2005 +0100 +++ b/tests/StringTest.java Sun Jan 23 01:01:40 2005 +0100 @@ -2,7 +2,7 @@ private String s; private String s2 = new String("abc"); private static String s3; - private static String s4 = new String("xyz"); + public static String s4 = new String("xyz"); public StringTest() { s = s2; @@ -15,4 +15,32 @@ public StringTest(String firstString, String secondString) { s = firstString + secondString; } + + public static void main(String[] args) { + if (StringTest.s4.equals("xyz")) { + System.out.println("StringTest.s4 correct: " + StringTest.s4); + } else { + System.err.println("StringTest.s4 failed!"); + } + StringTest test0 = new StringTest(); + if (test0.s.equals("abc")) { + System.out.println("test0.s correct: " + test0.s); + } else { + System.err.println("test0.s failed!"); + } + StringTest test1 = new StringTest("Test"); + if (test1.s.equals("Test")) { + System.out.println("test1.s correct: " + test1.s); + } else { + System.err.println("test1.s failed!"); + } + StringTest test2 = new StringTest("Hello ", "world"); + if (test2.s.equals("Hello world")) { + System.out.println("test2.s correct: " + test2.s); + } else { + System.err.println("test2.s failed!"); + } + } } + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 904c1223e3aa -r 1dc70ce13680 tests/SwitchTest.java --- a/tests/SwitchTest.java Sun Jan 23 01:01:34 2005 +0100 +++ b/tests/SwitchTest.java Sun Jan 23 01:01:40 2005 +0100 @@ -18,4 +18,30 @@ return x; } + + public static void main(String[] args) { + SwitchTest test = new SwitchTest(); + if (test.test(0) == 10) { + System.out.println("test.test(0) correct: " + test.test(0)); + } else { + System.err.println("test.test(0) failed!"); + } + if (test.test(1) == 11) { + System.out.println("test.test(1) correct: " + test.test(1)); + } else { + System.err.println("test.test(1) failed!"); + } + if (test.test(2) == 22) { + System.out.println("test.test(2) correct: " + test.test(2)); + } else { + System.err.println("test.test(2) failed!"); + } + if (test.test(3) == 3) { + System.out.println("test.test(3) correct: " + test.test(3)); + } else { + System.err.println("test.test(3) failed!"); + } + } } + +// vim: tabstop=4 expandtab shiftwidth=4 diff -r 904c1223e3aa -r 1dc70ce13680 tests/ValueSubclass.java --- a/tests/ValueSubclass.java Sun Jan 23 01:01:34 2005 +0100 +++ b/tests/ValueSubclass.java Sun Jan 23 01:01:40 2005 +0100 @@ -29,9 +29,50 @@ public void setValueObject(Value v) { this.value = v.getValue(); } + + /** + * Test program. + */ + public static void main(String[] args) { + SubclassValue sv = new SubclassValue(686); + if (sv.getValue() == 686) { + System.out.println("sv.getValue() correct: " + sv.getValue()); + } else { + System.err.println("sv.getValue() failed!"); + } + + ValueSubclass vs = new ValueSubclass(109); + if (vs.tmp.getValue() == 42) { + System.out.println("vs.tmp.getValue() correct: " + vs.tmp.getValue()); + } else { + System.err.println("vs.tmp.getValue() failed!"); + } + if (vs.getValue() == 109) { + System.out.println("vs.getValue() correct: " + vs.getValue()); + } else { + System.err.println("vs.getValue() failed!"); + } + vs.setValue(404); + if (vs.getValue() == -404) { + System.out.println("vs.getValue() correct: " + vs.getValue()); + } else { + System.err.println("vs.getValue() failed!"); + } + if (vs.add(404) == -808) { + System.out.println("vs.add(404) correct: " + vs.add(404)); + } else { + System.err.println("vs.add(404) failed!"); + } + vs.setValueObject(sv); + if (vs.getValue() == 686) { + System.out.println("vs.getValue() correct: " + vs.getValue()); + } else { + System.err.println("vs.getValue() failed!"); + } + } } -// This should confuse the importer since it should be read before Value in +// This would confuse a simple importer since it should be read before Value in // alphabetical order. class SubclassValue extends Value { @@ -39,3 +80,5 @@ super(x); } } + +// vim: tabstop=4 expandtab shiftwidth=4