javaclass

Annotated tests/ValueSubclass.java

146:1dc70ce13680
2005-01-23 Paul Boddie Added more tests.
paul@20 1
public class ValueSubclass extends Value {
paul@30 2
    public Value tmp;
paul@20 3
paul@28 4
    /**
paul@28 5
     * Test of subclass initialisation with super usage and foreign object initialisation.
paul@28 6
     */
paul@20 7
    public ValueSubclass(int x) {
paul@20 8
        super(x);
paul@30 9
        tmp = new Value(42);
paul@28 10
    }
paul@28 11
paul@28 12
    /**
paul@28 13
     * Test of overriding.
paul@28 14
     */
paul@28 15
    public void setValue(int x) {
paul@28 16
        this.value = -x;
paul@28 17
    }
paul@28 18
paul@28 19
    /**
paul@28 20
     * Test of overriding and super methods.
paul@28 21
     */
paul@28 22
    public int add(int x) {
paul@28 23
        return super.add(-x);
paul@28 24
    }
paul@28 25
paul@28 26
    /**
paul@28 27
     * Test of objects as arguments.
paul@28 28
     */
paul@28 29
    public void setValueObject(Value v) {
paul@28 30
        this.value = v.getValue();
paul@20 31
    }
paul@146 32
paul@146 33
    /**
paul@146 34
     * Test program.
paul@146 35
     */
paul@146 36
    public static void main(String[] args) {
paul@146 37
        SubclassValue sv = new SubclassValue(686);
paul@146 38
        if (sv.getValue() == 686) {
paul@146 39
            System.out.println("sv.getValue() correct: " + sv.getValue());
paul@146 40
        } else {
paul@146 41
            System.err.println("sv.getValue() failed!");
paul@146 42
        }
paul@146 43
        
paul@146 44
        ValueSubclass vs = new ValueSubclass(109);
paul@146 45
        if (vs.tmp.getValue() == 42) {
paul@146 46
            System.out.println("vs.tmp.getValue() correct: " + vs.tmp.getValue());
paul@146 47
        } else {
paul@146 48
            System.err.println("vs.tmp.getValue() failed!");
paul@146 49
        }
paul@146 50
        if (vs.getValue() == 109) {
paul@146 51
            System.out.println("vs.getValue() correct: " + vs.getValue());
paul@146 52
        } else {
paul@146 53
            System.err.println("vs.getValue() failed!");
paul@146 54
        }
paul@146 55
        vs.setValue(404);
paul@146 56
        if (vs.getValue() == -404) {
paul@146 57
            System.out.println("vs.getValue() correct: " + vs.getValue());
paul@146 58
        } else {
paul@146 59
            System.err.println("vs.getValue() failed!");
paul@146 60
        }
paul@146 61
        if (vs.add(404) == -808) {
paul@146 62
            System.out.println("vs.add(404) correct: " + vs.add(404));
paul@146 63
        } else {
paul@146 64
            System.err.println("vs.add(404) failed!");
paul@146 65
        }
paul@146 66
        vs.setValueObject(sv);
paul@146 67
        if (vs.getValue() == 686) {
paul@146 68
            System.out.println("vs.getValue() correct: " + vs.getValue());
paul@146 69
        } else {
paul@146 70
            System.err.println("vs.getValue() failed!");
paul@146 71
        }
paul@146 72
    }
paul@20 73
}
paul@58 74
paul@146 75
// This would confuse a simple importer since it should be read before Value in
paul@58 76
// alphabetical order.
paul@58 77
paul@58 78
class SubclassValue extends Value {
paul@58 79
    public SubclassValue(int x) {
paul@58 80
        super(x);
paul@58 81
    }
paul@58 82
}
paul@146 83
paul@146 84
// vim: tabstop=4 expandtab shiftwidth=4