001: package org.hanseltest.probes;
002:
003: import junit.framework.TestCase;
004:
005: import org.hansel.probes.EQComparator;
006: import org.hansel.probes.GEComparator;
007: import org.hansel.probes.GTComparator;
008: import org.hansel.probes.LEComparator;
009: import org.hansel.probes.LTComparator;
010: import org.hansel.probes.NEComparator;
011: import org.hansel.stack.HanselValue;
012:
013: /**
014: * Tests for the org.hansel.probe.*Comparator classes.
015: *
016: * @author Niklas Mehner
017: */
018: public class IntComparatorTest extends TestCase {
019: private static HanselValue op1 = new HanselValue("op1", false, 1);
020: private static HanselValue op2 = new HanselValue("op2", false, 1);
021:
022: /**
023: * Create a new Test.
024: * @param name Name of the test.
025: */
026: public IntComparatorTest(String name) {
027: super (name);
028: }
029:
030: /**
031: * Test the EQComparator.
032: */
033: public void testEQComparator() {
034: EQComparator eq = new EQComparator();
035: assertEquals(6, eq.getPrecedence());
036: assertEquals("==", eq.getSign());
037: assertTrue(eq.compare(0, 0));
038: assertTrue(!eq.compare(1, 0));
039:
040: assertEquals("op1 == op2", eq.createStackEntry(op1, op2)
041: .toString());
042: }
043:
044: /**
045: * Test the NEComparator.
046: */
047: public void testNEComparator() {
048: NEComparator ne = new NEComparator();
049: assertEquals(6, ne.getPrecedence());
050: assertEquals("!=", ne.getSign());
051: assertTrue(!ne.compare(0, 0));
052: assertTrue(ne.compare(1, 0));
053:
054: assertEquals("op1 != op2", ne.createStackEntry(op1, op2)
055: .toString());
056: }
057:
058: /**
059: * Test the GTComparator.
060: */
061: public void testGTComparator() {
062: GTComparator gt = new GTComparator();
063: assertEquals(5, gt.getPrecedence());
064: assertEquals(">", gt.getSign());
065: assertTrue(!gt.compare(0, 0));
066: assertTrue(!gt.compare(5, 7));
067: assertTrue(gt.compare(8, 7));
068:
069: assertEquals("op1 > op2", gt.createStackEntry(op1, op2)
070: .toString());
071: }
072:
073: /**
074: * Test the GEComparator.
075: */
076: public void testGEComparator() {
077: GEComparator ge = new GEComparator();
078: assertEquals(5, ge.getPrecedence());
079: assertEquals(">=", ge.getSign());
080: assertTrue(ge.compare(0, 0));
081: assertTrue(!ge.compare(5, 7));
082: assertTrue(ge.compare(8, 7));
083:
084: assertEquals("op1 >= op2", ge.createStackEntry(op1, op2)
085: .toString());
086: }
087:
088: /**
089: * Test the LTComparator.
090: */
091: public void testLTComparator() {
092: LTComparator lt = new LTComparator();
093: assertEquals(5, lt.getPrecedence());
094: assertEquals("<", lt.getSign());
095: assertTrue(!lt.compare(0, 0));
096: assertTrue(lt.compare(5, 7));
097: assertTrue(!lt.compare(8, 7));
098:
099: assertEquals("op1 < op2", lt.createStackEntry(op1, op2)
100: .toString());
101: }
102:
103: /**
104: * Test the LEComparator.
105: */
106: public void testLEComparator() {
107: LEComparator le = new LEComparator();
108: assertEquals(5, le.getPrecedence());
109: assertEquals("<=", le.getSign());
110: assertTrue(le.compare(0, 0));
111: assertTrue(le.compare(5, 7));
112: assertTrue(!le.compare(8, 7));
113:
114: assertEquals("op1 <= op2", le.createStackEntry(op1, op2)
115: .toString());
116: }
117:
118: }
|