public IntRangeVal(String name, int min, int max) { super(name); this.min = min; this.max = max;
}
publicint getVal() { return v;
}
public String toString() { return name+" = "+v;
}
public Object save() { returnnew Integer(v);
}
publicvoid restore(Object o) {
v = ((Integer) o).intValue();
}
publicvoid randomize() {
v = min + (int) (Math.random() * (max-min+1));
}
publicvoid perturb() {
v = v + 1; if (v > max) {
v = min;
}
}
}
/** *Baseclassfortestingagiventypeofshape. *Subclassesmustregisteralloftheir"parameters"which *needtoberandomized,specialized,andperturbedfor *testing. *SubclassesmustalsoimplementmakeShape()whichmakes *anewshapeobjectaccordingtothecurrentvaluesof *alloftheirparameters.
*/ publicstaticabstractclass ShapeTester { public Vector params = new Vector();
publicvoid addParam(Val v) {
params.add(v);
}
public Val[] getParamArray() {
Val ret[] = new Val[params.size()]; for (int i = 0; i < params.size(); i++) {
ret[i] = (Val) params.get(i);
} return ret;
}
publicvoid test() {
Val params[] = getParamArray(); for (int i = 0; i < NUMTESTS; i++) { // First, randomize all parameters for (int j = 0; j < params.length; j++) {
params[j].randomize();
}
// Now make 2 copies from the same params and verify equals()
Object o1 = makeShape(); if (!o1.equals(o1)) {
error("Shapes not equal to itself!");
}
Object o2 = makeShape(); if (!o1.equals(o2)) {
error("Identical shapes not equal!");
} if (o1.hashCode() != o2.hashCode()) {
error("Identical hashes not equal!");
}
// Now perturb the params 1 by 1 and verify !equals() for (int j = 0; j < params.length; j++) {
Val param = params[j];
Object save = param.save();
param.perturb();
Object o3 = makeShape(); if (o1.equals(o3)) {
error("Perturbed shape still equal!");
}
// If param has "special values", test them as well if (param instanceof SpecialVal) {
SpecialVal sparam = (SpecialVal) param;
sparam.setSpecial();
Object o4 = makeShape(); if (o1.equals(o4)) {
error("Specialized shape still equal!");
}
Object o5 = makeShape(); // objects equal iff param is not a NaN if (o4.equals(o5) == sparam.isNaN()) {
error("Identical specialized shapes not equal!");
} // hash codes always equal, even if NaN // (Note: equals()/hashCode() contract allows this) if (o4.hashCode() != o5.hashCode()) {
error("Identical specialized hashes not equal!");
}
}
// Restore original value of param and make sure
param.restore(save);
Object o6 = makeShape(); if (!o1.equals(o6)) {
error("Restored shape not equal!");
} if (o1.hashCode() != o6.hashCode()) {
error("Restored hash not equal!");
}
}
}
}
}
/** *Basetesterclassforobjectswithfloatingpointxywhbounds
*/ publicstaticabstractclass FloatBoundedShape extends ShapeTester { public FloatVal x = new FloatVal("x"); public FloatVal y = new FloatVal("y"); public FloatVal w = new FloatVal("w"); public FloatVal h = new FloatVal("h");
public FloatBoundedShape() {
addParam(x);
addParam(y);
addParam(w);
addParam(h);
}
}
/** *Basetesterclassforobjectswithdoubleprecisionxywhbounds
*/ publicstaticabstractclass DoubleBoundedShape extends ShapeTester { public DoubleVal x = new DoubleVal("x"); public DoubleVal y = new DoubleVal("y"); public DoubleVal w = new DoubleVal("w"); public DoubleVal h = new DoubleVal("h");
public DoubleBoundedShape() {
addParam(x);
addParam(y);
addParam(w);
addParam(h);
}
}
publicstaticclass FloatArcTester extends FloatBoundedShape { public FloatVal start = new FloatVal("start"); public FloatVal extent = new FloatVal("extent"); public IntRangeVal type = new IntRangeVal("type", 0, 2);
public FloatArcTester() {
addParam(start);
addParam(extent);
addParam(type);
}
publicstaticclass DoubleArcTester extends DoubleBoundedShape { public DoubleVal start = new DoubleVal("start"); public DoubleVal extent = new DoubleVal("extent"); public IntRangeVal type = new IntRangeVal("type", 0, 2);
public DoubleArcTester() {
addParam(start);
addParam(extent);
addParam(type);
}
publicstaticclass FloatRoundRectTester extends FloatBoundedShape { public FloatVal arcw = new FloatVal("arcw"); public FloatVal arch = new FloatVal("arch");
public FloatRoundRectTester() {
addParam(arcw);
addParam(arch);
}
publicstaticclass DoubleRoundRectTester extends DoubleBoundedShape { public DoubleVal arcw = new DoubleVal("arcw"); public DoubleVal arch = new DoubleVal("arch");
public DoubleRoundRectTester() {
addParam(arcw);
addParam(arch);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.