class TestIntList { /** Sample IntList values */ static final oneElt = new Cons(1, Empty.ONLY); static final twoElts = new Cons(5, oneElt); static final threeElts = new Cons(-10, twoElts); /** Test the sum() method, assuming that ans is * the correct answer for this.sum() */ void testSum(int ans) { int result = sum(); System.out.println("computed sum of " + this + " = " + sum()); if (result != ans) System.out.println("FAILURE: correct answer is " + ans); } /** Test driver method */ public void test() { Empty.ONLY.testSum(0); Cons.oneElt.testSum(1); Cons.twoElts.testSum(6); Cons.threeElts.testSum(-4); } }