scribbledecobble
scribbledecobble.blogspot.com
Pages
Home
Contents
A
…
K
My List Should
public class MyList { public static void main(String args[]) { MyListShould.testGetFirst(); } } class MyListShould { static void testGetFirst() { final String[][] inputs = { null, {}, {""}, {"a"}, {"1"}, {"\"\""}, {"\"\n\""}, {"abc", "xyz"}, }; final int n = inputs.length; final String [] expectedOutputs = new String[n]; expectedOutputs[0] = expectedOutputs[1] = null; int i = 2; while (i < n) { expectedOutputs[i] = inputs[i][0]; i = i + 1; } System.out.println("Testing MyList.getFirst"); for (i = 0; i < n; i++) { String[] input = inputs[i]; String expected = expectedOutputs[i]; System.out.println("\nTest: " + i); System.out.println("Expect: " + expected); try { String actual = MyList.getFirst(input); System.out.println("Actual: " + actual); String r = (expected == actual) ? "PASS" : "FAIL"; System.out.println("Result: " + r); } catch(Exception e) { System.out.println("\nAn exception was thrown."); System.out.println(e.toString()); System.out.println("Test aborted."); } } } }
Newer Post
Older Post
Home