Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Class Variables
- public static int numTests = 0;
- public static int numPassedTests = 0;
- ## main Method
- lets1 = new LetterInventory("!@*$&%^@)!)@($(#&&!&!((");
- runTest(0, lets1.size());
- runTest("", lets1.toString());
- for(char c = 'a'; c <= 'z'; c++) {
- runTest(0, lets1.get(c));
- }
- for(char c = 'A'; c <= 'Z'; c++) {
- runTest(0, lets1.get(c));
- }
- runTest(lets2, lets1.add(lets2));
- runTest(null, lets1.subtract(lets2));
- runTest(true, lets1.isEmpty());
- for(char c = 'a'; c <= 'z'; c++)
- lets1.set(c, 1);
- for(char c = 'a'; c <= 'z'; c++)
- runTest(1, lets1.get(c));
- for(char c = 'A'; c <= 'Z'; c++)
- runTest(1, lets1.get(c));
- runTest(26, lets1.size());
- runTest(false, lets1.isEmpty());
- runTest("abcdefghijklmnopqrstuvwxyz", lets1.toString());
- for(char c = 'A'; c <= 'Z'; c++)
- lets1.set(c, 2);
- for(char c = 'a'; c <= 'z'; c++)
- runTest(2, lets1.get(c));
- for(char c = 'A'; c <= 'Z'; c++)
- runTest(2, lets1.get(c));
- runTest(52, lets1.size());
- runTest(false, lets1.isEmpty());
- runTest("aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", lets1.toString());
- runTest(true, lets1.equals(lets1));
- runTest(lets1, lets1);
- lets1 = new LetterInventory("joe");
- lets2 = new LetterInventory("bob");
- lets4 = new LetterInventory("bobjoe");
- runTest(false, lets1.equals(lets2));
- runTest(false, lets2.equals(lets1));
- runTest(false, lets1.equals(lets4));
- runTest(false, lets4.equals(lets1));
- runTest(false, lets2.equals(lets4));
- runTest(false, lets4.equals(lets2));
- runTest(lets4, lets1.add(lets2));
- runTest(lets1, lets4.subtract(lets2));
- runTest(lets2, lets4.subtract(lets1)); // test 200
- lets1 = new LetterInventory("ÀÃÆÇÈî‰|µ¶¿ÿ");
- runTest(0, lets1.size());
- runTest("", lets1.toString());
- runTest(false, lets1.equals('È'));
- try { lets1.get('È'); runErroringTest(false); } catch (AssertionError e) { runErroringTest(true); }
- try { lets1.set('È', 800); runErroringTest(false); } catch (AssertionError e) { runErroringTest(true); }
- System.out.println();
- System.out.println("Passed " + numPassedTests + "/" + numTests);
- ## Testing Helper Methods
- // Modified a bit from the original method Mike gave us to keep track of # tests & # that pass
- public static boolean showTestResults(Object expected, Object actual, int testNum, String featureTested) {
- numTests++;
- System.out.println("Test Number " + testNum + " testing " + featureTested);
- System.out.println("Expected result: " + expected);
- System.out.println("Actual result: " + actual);
- boolean passed = (actual == null && expected == null) || actual.equals(expected);
- if(passed) {
- numPassedTests++;
- System.out.println("Passed test " + testNum);
- } else
- System.out.println("!!! FAILED TEST !!! " + testNum);
- System.out.println();
- return passed;
- }
- private static void runTest(int expected, int actual) {
- numTests++;
- if( expected == actual ) {
- numPassedTests++;
- System.out.print("Test " + numTests + " expected value: " + expected + ", actual value: " + actual);
- } else {
- System.out.print("FAILURE -- Test " + numTests + " expected value: " + expected + ", actual value: " + actual);
- }
- System.out.println();
- }
- private static void runTest(String expected, String actual) {
- numTests++;
- if( expected.equals(actual) ) {
- numPassedTests++;
- System.out.print("Test " + numTests + " expected value: " + expected + ", actual value: " + actual);
- } else {
- System.out.print("FAILURE -- Test " + numTests + " expected value: " + expected + ", actual value: " + actual);
- }
- System.out.println();
- }
- private static void runTest(boolean expected, boolean actual) {
- numTests++;
- if( expected == actual ) {
- numPassedTests++;
- System.out.print("Test " + numTests + " expected value: " + expected + ", actual value: " + actual);
- } else {
- System.out.print("FAILURE -- Test " + numTests + " expected value: " + expected + ", actual value: " + actual);
- }
- System.out.println();
- }
- private static void runTest(Object expected, Object actual) {
- numTests++;
- if( (expected == null && actual == null) || expected.equals(actual) ) {
- numPassedTests++;
- System.out.print("Test " + numTests + " expected value: " + expected + ", actual value: " + actual);
- } else {
- System.out.print("FAILURE -- Test " + numTests + " expected value: " + expected + ", actual value: " + actual);
- }
- System.out.println();
- }
- private static void runErroringTest(boolean failed) {
- numTests++;
- if( failed ) {
- numPassedTests++;
- System.out.print("Test " + numTests + " sucessfully failed");
- } else {
- System.out.print("FAILURE -- Test " + numTests + " did not fail");
- }
- System.out.println();
- }
Add Comment
Please, Sign In to add comment