01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fit;
04:
05: import junit.framework.TestCase;
06:
07: public class FitMatcherTest extends TestCase {
08: private void assertMatch(String expression, Number parameter)
09: throws Exception {
10: FitMatcher matcher = new FitMatcher(expression, parameter);
11: assertTrue(matcher.matches());
12: }
13:
14: private void assertNoMatch(String expression, Number parameter)
15: throws Exception {
16: FitMatcher matcher = new FitMatcher(expression, parameter);
17: assertFalse(matcher.matches());
18: }
19:
20: private void assertException(String expression, Object parameter) {
21: FitMatcher matcher = new FitMatcher(expression, parameter);
22: try {
23: matcher.matches();
24: fail();
25: } catch (Exception e) {
26: }
27: }
28:
29: public void testSimpleMatches() throws Exception {
30: assertMatch("_<3", new Integer(2));
31: assertNoMatch("_<3", new Integer(3));
32: assertMatch("_<4", new Integer(3));
33: assertMatch("_ < 9", new Integer(4));
34: assertMatch("<3", new Integer(2));
35: assertMatch(">4", new Integer(5));
36: assertMatch(">-3", new Integer(-2));
37: assertMatch("<3.2", new Double(3.1));
38: assertNoMatch("<3.2", new Double(3.3));
39: assertMatch("<=3", new Double(3));
40: assertMatch("<=3", new Double(2));
41: assertNoMatch("<=3", new Double(4));
42: assertMatch(">=2", new Double(2));
43: assertMatch(">=2", new Double(3));
44: assertNoMatch(">=2", new Double(1));
45: }
46:
47: public void testExceptions() throws Exception {
48: assertException("X", new Integer(1));
49: assertException("<32", "xxx");
50: }
51:
52: public void testMessage() throws Exception {
53: FitMatcher matcher = new FitMatcher("_>25", new Integer(3));
54: assertEquals("<b>3</b>>25", matcher.message());
55: matcher = new FitMatcher(" < 32", new Integer(5));
56: assertEquals("<b>5</b> < 32", matcher.message());
57: }
58:
59: public void testTrichotomy() throws Exception {
60: assertMatch("5<_<32", new Integer(8));
61: assertNoMatch("5<_<32", new Integer(5));
62: assertNoMatch("5<_<32", new Integer(32));
63: assertMatch("10>_>5", new Integer(6));
64: assertNoMatch("10>_>5", new Integer(10));
65: assertNoMatch("10>_>5", new Integer(5));
66: assertMatch("10>=_>=5", new Integer(10));
67: assertMatch("10>=_>=5", new Integer(5));
68: }
69:
70: }
|