01: /*
02: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18: package test.org.mandarax.lib.math;
19:
20: import java.util.Collection;
21: import java.util.Vector;
22:
23: import org.mandarax.util.AutoFacts;
24:
25: /**
26: * Superclass for testing predicates and functions for integers from the math package.
27: * All tests work as follows: we build an auto fact set, fetch an iterator and
28: * count the facts generated. The number of facts is compared with the expected number of facts.
29: * Facts are printed out on System.out.
30: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
31: * @version 3.4 <7 March 05>
32: * @since 1.6
33: */
34: public abstract class IntArithmeticTest extends MathTestCase {
35:
36: /**
37: * IntArithmeticTest constructor comment.
38: */
39: public IntArithmeticTest() {
40: super ();
41: }
42:
43: /**
44: * Get the auto facts.
45: * @return an auto facts clause set
46: */
47: protected AutoFacts getAutoFacts() {
48: final Vector ext = new Vector();
49: int[] testSet = getTestSet();
50:
51: for (int i = 0; i < testSet.length; i++) {
52: ext.add(new Integer(testSet[i]));
53: }
54:
55: return new AutoFacts() {
56:
57: public Collection getExtension(Class clazz) {
58: if (clazz == Integer.class) {
59: return ext;
60: } else {
61: return super .getExtension(clazz);
62: }
63: }
64: };
65: }
66:
67: /**
68: * Get the set of numbers used for testing.
69: * @return an array of doubles
70: */
71: protected abstract int[] getTestSet();
72:
73: /**
74: * Get the type (e.g. Integer.class or Double.class) we want to test.
75: * @return the type to be tested
76: */
77: protected Class getType() {
78: return Integer.class;
79: }
80: }
|