Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestHelper {
- private static int testNum = 0;
- /**
- * given two objects, expected and result, sout that the test passes if result.equals(expected) otherwise sout failure.
- * and provide information on the class that this test pertains to.
- * @param clazz
- * @param expected
- * @param result
- * @param description
- */
- public static void evaluateTest(Class clazz,Object expected, Object result, String description){
- if(result.equals(expected)){
- System.out.println("Passed Test(" + clazz.getName()+ ") " + testNum++ + ": " + description);
- }else{
- System.out.println("Failed Test(" + clazz.getName()+ ") " + testNum++ + ": " + description);
- System.out.println("Expected: " + expected + ", actual: " + result);
- }
- }
- }
- /* Sample usage/output below *********************************************/
- //Sample setup and usage
- HangmanManager hangmanManager = new HangmanManager(HangmanMain.getDictionary()); //actually quick hack to make getting the dictionary easier >.<
- int expectedInt;
- Map<String, Integer> expectedMap;
- //numWords(len)
- expectedInt = 49;
- TestHelper.evaluateTest(HangmanManager.class, expectedInt, hangmanManager.numWords(2), "Testing numWords method for words of length 2");
- expectedInt = 7359;
- TestHelper.evaluateTest(HangmanManager.class, expectedInt, hangmanManager.numWords(7), "Testing numWords method for words of length 7");
- //sample output
- Passed Test(HangmanManager) 0: Testing numWords method for words of length 2
- Passed Test(HangmanManager) 1: Testing numWords method for words of length 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement