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