KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > core > constraint > IsCloseToTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package test.jmock.core.constraint;
4
5 import org.jmock.core.constraint.IsCloseTo;
6
7
8 public class IsCloseToTest extends AbstractConstraintsTest
9 {
10
11     public void testEvaluatesToTrueIfArgumentIsEqualToADoubleValueWithinSomeError() {
12         IsCloseTo p = new IsCloseTo(1.0, 0.5);
13
14         assertTrue(p.eval(new Double JavaDoc(1.0)));
15         assertTrue(p.eval(new Double JavaDoc(0.5)));
16         assertTrue(p.eval(new Double JavaDoc(1.5)));
17
18         assertTrue(p.eval(new Float JavaDoc(1.0)));
19         assertTrue(p.eval(new Integer JavaDoc(1)));
20
21         assertTrue("number too large", !p.eval(new Double JavaDoc(2.0)));
22         assertTrue("number too small", !p.eval(new Double JavaDoc(0.0)));
23
24         try {
25             p.eval("wrong type");
26             fail("ClassCastException expected for wrong type of argument");
27         }
28         catch (ClassCastException JavaDoc ex) {
29             // expected
30
}
31     }
32
33 }
34
Popular Tags