Want more features on Pastebin? Sign Up, it's FREE!
Guest

Java Doop2.0!

By: a guest on Sep 29th, 2011  |  syntax: Java  |  size: 1.63 KB  |  views: 249  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class TestHelper {
  2.  
  3.     private static int testNum = 0;
  4.     /**
  5.      * given two objects, expected and result, sout that the test passes if result.equals(expected) otherwise sout failure.
  6.      * and provide information on the class that this test pertains to.
  7.      * @param clazz
  8.      * @param expected
  9.      * @param result
  10.      * @param description
  11.      */
  12.     public static void evaluateTest(Class clazz,Object expected, Object result, String description){
  13.         if(result.equals(expected)){
  14.             System.out.println("Passed Test(" + clazz.getName()+ ") " + testNum++ + ": " + description);
  15.         }else{
  16.             System.out.println("Failed Test(" + clazz.getName()+ ") " + testNum++ + ": " + description);
  17.             System.out.println("Expected: " + expected + ", actual: " + result);
  18.         }
  19.     }
  20. }
  21.  
  22. /* Sample usage/output below *********************************************/
  23. //Sample setup and usage
  24. HangmanManager hangmanManager = new HangmanManager(HangmanMain.getDictionary()); //actually quick hack to make getting the dictionary easier >.<
  25. int expectedInt;
  26. Map<String, Integer>  expectedMap;
  27.  
  28. //numWords(len)
  29. expectedInt = 49;
  30. TestHelper.evaluateTest(HangmanManager.class, expectedInt, hangmanManager.numWords(2), "Testing numWords method for words of length 2");
  31.  
  32. expectedInt = 7359;
  33. TestHelper.evaluateTest(HangmanManager.class, expectedInt, hangmanManager.numWords(7), "Testing numWords method for words of length 7");
  34.  
  35. //sample output
  36. Passed Test(HangmanManager) 0: Testing numWords method for words of length 2
  37. Passed Test(HangmanManager) 1: Testing numWords method for words of length 7
  38.  
  39.  
clone this paste RAW Paste Data