class IntListTest { static final IntList oneElt = new Cons(1, Empty.ONLY); static final IntList twoElts = new Cons(5, oneElt); static final IntList threeElts = new Cons(-10, twoElts); /** Given the the answer ans, computes the sum() on this and * compares it against ans. If the values disagree, it throws an * exception with an embedded error message; otherwise it * silently returns. */ void test(IntList input, int ans) { int result = input.sum(); if (result != ans) throw new RuntimeException("Test FAILURE: computed answer is: " + result + " correct answer is: " + ans); } void sumTest() { test(Empty.ONLY, 0); test(oneElt, 1); test(twoElts, 6); test(threeElts, -4); } }