Created
October 27, 2016 14:18
-
-
Save shreydesai/985fd7a5eeacad5d9c2579bdd3d140a2 to your computer and use it in GitHub Desktop.
CS 314 Assignment 8 Tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static boolean test(Object exp, Object actual, String test) { | |
String output = null; | |
if (exp.equals(actual)) { | |
output = "✔ Passed " + test; | |
System.out.println(output + "\n"); | |
return true; | |
} | |
output = "***** FAILED ***** " + test + "\n" + | |
"Expected: " + exp + ", Actual: " + actual; | |
System.out.println(output + "\n"); | |
return false; | |
} | |
private static void cs314StudentTestsForLetterInventory() { | |
// Constructor - Test 1 | |
LetterInventory inv = new LetterInventory("dog"); | |
test(3, inv.size(), "Constructor - Test 1a"); | |
test("dgo", inv.toString(), "Constructor - Test 1b"); | |
// Constructor - Test 2 | |
inv = new LetterInventory(""); | |
test(0, inv.size(), "Constructor - Test 2a"); | |
test("", inv.toString(), "Constructor - Test 2b"); | |
// get - Test 1 | |
inv = new LetterInventory("ThE cAt JuMpEd!!!"); | |
test(2, inv.get('e'), "get - Test 1"); | |
// get - Test 2 | |
inv = new LetterInventory("!!$@^$fF!%kd(#()#"); | |
test(2, inv.get('f'), "get - Test 2"); | |
// size - Test 1 | |
inv = new LetterInventory("I@want@some@ice@cream!!!"); | |
test(17, inv.size(), "size - Test 1"); | |
// size - Test 2 | |
inv = new LetterInventory("#*(#&!&(@*)*@)(*$)(@*"); | |
test(0, inv.size(), "size - Test 2"); | |
// isEmpty - Test 1 | |
inv = new LetterInventory("Dogs are great!"); | |
test(false, inv.isEmpty(), "isEmpty - Test 1a"); | |
LetterInventory result = inv.subtract(inv); | |
test(true, result.isEmpty(), "isEmpty - Test 1b"); | |
// isEmpty - Test 2 | |
inv = new LetterInventory(""); | |
test(true, inv.isEmpty(), "isEmpty - Test 2a"); | |
result = inv.add(new LetterInventory("CS314")); | |
result = result.subtract(new LetterInventory("cs")); | |
test(true, result.isEmpty(), "isEmpty - Test 2b"); | |
// add - Test 1 | |
inv = new LetterInventory("I love dogs"); | |
test(9, inv.size(), "add - Test 1a"); | |
result = inv.add(new LetterInventory("love")); | |
test(13, result.size(), "add - Test 1b"); | |
test("deegillooosvv", result.toString(), "add - Test 1c"); | |
// add - Test 2 | |
inv = new LetterInventory("#(!()@*#)(&!)@(#*"); | |
test(0, inv.size(), "add - Test 2a"); | |
result = inv.add(new LetterInventory("CS 314")); | |
test(2, result.size(), "add - Test 2b"); | |
// subtract - Test 1 | |
inv = new LetterInventory("love"); | |
test(4, inv.size(), "subtract - Test 1a"); | |
result = inv.subtract(new LetterInventory("love")); | |
test(0, result.size(), "subtract - Test 1b"); | |
// subtract - Test 2 | |
inv = new LetterInventory("CS 314 is fun"); | |
test(7, inv.size(), "subtract - Test 2a"); | |
result = inv.subtract(new LetterInventory("cs")); | |
test(5, result.size(), "subtract - Test 2b"); | |
// toString - Test 1 | |
inv = new LetterInventory("abcdef"); | |
test("abcdef", inv.toString(), "toString - Test 1"); | |
// toString - Test 2 | |
inv = new LetterInventory("@)(!@*)cs314(*)$(*$"); | |
test("cs", inv.toString(), "toString - Test 2"); | |
// equals - Test 1 | |
inv = new LetterInventory("I like my friends"); | |
LetterInventory inv2 = new LetterInventory("mild reef ski yin"); | |
test(true, inv.equals(inv2), "equals - Test 1"); | |
// equals - Test 2 | |
inv = new LetterInventory(""); | |
inv2 = new LetterInventory("@(!)@($&!)@(#*!)(@&$"); | |
test(true, inv.equals(inv2), "equals - Test 2"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment