/** This class has two (different) sorts of methods: * - methods for * */ public class TestUtils { /** If two booleans aren't equal, print an error message. * Intended for use as a test-helper. * @param act The actual boolean returned by a test call. * @param exp The expected boolean to be returned by a test call. */ public static void equalBools(boolean act, boolean exp) { if (act==exp) { System.out.println("(test passed)"); } else { System.out.println( "Actual: " + act + "\nExpect: " + exp ); } } /** If two ints aren't equal, print an error message. * Intended for use as a test-helper. * @param act The actual int returned by a test call. * @param exp The expected int to be returned by a test call. */ public static void equalInts(int act, int exp) { if (act==exp) { System.out.println("(test passed)"); } else { System.out.println( "Actual: " + act + "\nExpect: " + exp ); } } /** If two ints aren't equal, print an error message. * Intended for use as a test-helper. * @param act The actual int returned by a test call. * @param exp The expected int to be returned by a test call. */ public static void equalChars(char act, char exp) { if (act==exp) { System.out.println("(test passed)"); } else { System.out.println( "Actual: " + act + "\nExpect: " + exp ); } } /** If two Strings aren't equal, print an error message. * Intended for use as a test-helper. * @param act The actual String returned by a test call. * @param exp The expected String to be returned by a test call. */ public static void equalStrings(String act, String exp) { if (act.equals(exp)) { System.out.println("(test passed)"); } else { System.out.println( "Actual: " + act + "\nExpect: " + exp ); } } /** If two doubles aren't (nearly) equal, print an error message. * Intended for use as a test-helper. * @param act The actual double returned by a test call. * @param exp The expected double to be returned by a test call. * @param tolerance The amount of tolerance allowed to still be considered equal * (an absolute amount.) * * BUG: the tolerance should probably be a relative to exp, at least when when exp!=0. */ public static void equalDoubles(double act, double exp, double tolerance) { if ( (act == exp) || (Math.abs(act-exp) < tolerance) || (Double.isNaN(act) && Double.isNaN(exp))) { System.out.println("(test passed)"); } else { System.out.println( "Actual: " + act + "\nExpect: " + exp ); } } /** If two doubles aren't (nearly) equal, print an error message. * Intended for use as a test-helper. * @param act The actual double returned by a test call. * @param exp The expected double to be returned by a test call. */ public static void equalDoubles(double act, double exp) { TestUtils.equalDoubles(act,exp,TOLERANCE); } /** default The tolerance for testEqualDoubles */ private static double TOLERANCE = 0.000001; }