/** Test comparator classes */

package FlexOr.container;

import java.util.Date;

public class ComparatorTest {
  
  public static void main (String arg[]) {
    println("Test started " + new Date());
    println("***** String comparators");
    testString();
    println("Test finished " + new Date());
  }

  public static void testString() {
    String a = "abc";
    String b = "bcd";
    String c = "abc";
    StringBuffer d = new StringBuffer("");
    
    BinaryPredicate bp = new StringLessThan();
    if (! bp.execute(a,b))
        println("1  " + a + " should be less than " + b);
    try { bp.execute(a,d);
    } catch (BinPredParamException e) { println("2 caught param exception"); }
    try { bp.execute(d,a);
    } catch (BinPredParamException e) { println("3 caught param exception"); }

    bp = new StringLessThanEqual();
    if (! bp.execute(a,b))
        println("4  " + a + " should be less than or eqaul " + b);
    if (! bp.execute(a,c))
        println("5  " + a + " should be less than or eqaul " + b);
    try { bp.execute(a,d);
    } catch (BinPredParamException e) { println("6 caught param exception"); }
    try { bp.execute(d,a);
    } catch (BinPredParamException e) { println("7 caught param exception"); }

    bp = new StringEqual();
    if (! bp.execute(a,c))
        println("8  " + a + " should equal " + b);
    try { bp.execute(a,d);
    } catch (BinPredParamException e) { println("9 caught param exception"); }
    try { bp.execute(d,a);
    } catch (BinPredParamException e) { println("10 caught param exception"); }

    bp = new StringNotEqual();
    if (! bp.execute(a,b))
        println("11  " + a + " should be not equal" + b);
    try { bp.execute(a,d);
    } catch (BinPredParamException e) { println("12 caught param exception"); }
    try { bp.execute(d,a);
    } catch (BinPredParamException e) { println("13 caught param exception"); }

    bp = new StringGreaterThanEqual();
    if (! bp.execute(b,a))
        println("14  " + a + " should be greater than or equal " + b);
    if (! bp.execute(a,c))
        println("15  " + a + " should be greater than or equal " + b);
    try { bp.execute(a,d);
    } catch (BinPredParamException e) { println("16 caught param exception"); }
    try { bp.execute(d,a);
    } catch (BinPredParamException e) { println("17 caught param exception"); }

    bp = new StringGreaterThan();
    if (! bp.execute(b,a))
        println("18  " + b + " should be less than " + a);
    try { bp.execute(a,d);
    } catch (BinPredParamException e) { println("19 caught param exception"); }
    try { bp.execute(d,a);
    } catch (BinPredParamException e) { println("20 caught param exception"); }
  }
  
  private static void println(String item) {
    System.out.println(item);
  }

}
