# HG changeset patch # User Paul Boddie # Date 1106065049 -3600 # Node ID 14c7f90abf1b0b1d79cc59db5be25585ba8f6d52 # Parent b220be071851b6f5a78938713776be09f6e8e398 Added a main method test program. diff -r b220be071851 -r 14c7f90abf1b tests/Value.java --- a/tests/Value.java Tue Jan 18 17:17:13 2005 +0100 +++ b/tests/Value.java Tue Jan 18 17:17:29 2005 +0100 @@ -34,6 +34,68 @@ public Value newValue() { return new Value(this.getValue()); } + + public static void main(String[] args) { + Value v = new Value(123); + if (v.getValue() != 123) { + System.err.println("v.getValue() failed!"); + } else { + System.out.println("v.getValue() correct: " + v.getValue()); + } + v.setValue(456); + if (v.getValue() != 456) { + System.err.println("v.setValue(456) or v.getValue() failed!"); + } else { + System.out.println("v.getValue() correct: " + v.getValue()); + } + if (!v.isPositive()) { + System.err.println("v.isPositive() failed!"); + } else { + System.out.println("v.isPositive() correct: " + v.isPositive()); + } + v.setValue(-789); + if (v.isPositive()) { + System.err.println("v.isPositive() failed!"); + } else { + System.out.println("v.isPositive() correct: " + v.isPositive()); + } + if (v.compare(-790) != -1) { + System.err.println("v.compare(-790) failed!"); + } else { + System.out.println("v.compare(-790) correct: " + v.compare(-790)); + } + if (v.compare(-788) != 1) { + System.err.println("v.compare() failed!"); + } else { + System.out.println("v.compare(-788) correct: " + v.compare(-788)); + } + if (v.compare(-789) != 0) { + System.err.println("v.compare() failed!"); + } else { + System.out.println("v.compare(-789) correct: " + v.compare(-789)); + } + Value v2 = v.newValue(); + if (v == v2) { + System.err.println("v.newValue() failed!"); + } + v2.setValue(123); + if (v.getValue() == v2.getValue()) { + System.err.println("v.newValue() failed (to establish separate members)!"); + } else { + System.out.println("v.getValue() == v2.getValue() correct: " + (v.getValue() == v2.getValue())); + } + if (v2.add(-123) != 0) { + System.err.println("v2.add(-123) failed!"); + } else { + System.out.println("v2.add(-123) correct: " + v2.add(-123)); + } + v2.setValue(255); + if (v2.getValue() != 255) { + System.err.println("v2.setValue(255) or v2.getValue() failed!"); + } else { + System.out.println("v2.getValue() correct: " + v2.getValue()); + } + } } // vim: tabstop=4 expandtab shiftwidth=4