import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.Random; import java.util.TreeMap; import java.util.TreeSet; /** * Lab 07 tester. * * javac *.java * java Lab07Tester * * Runs every check and keeps going after a failure, then prints a summary. * A method that still has its "not written yet" line is reported as SKIP, so * you can run this after every task. * * Besides calling your methods, it looks INSIDE your table: it reads the fields * nodes and size, and key, value, and next in Node, from the provided * HashMap.java, so keep those names. */ public class Lab07Tester { private static int passed = 0, failed = 0, skipped = 0; private static void check(boolean condition, String message) { if (condition) { passed++; System.out.println(" [PASS] " + message); } else { fail(message); } } private static boolean checkEquals(Object shouldBe, Object yours, String message) { boolean same = shouldBe == null ? yours == null : shouldBe.equals(yours); if (same) { check(true, message); } else { fail(message + "\n should be: " + shouldBe + "\n yours: " + yours); } return same; } private static void fail(String message) { failed++; System.out.println(" [FAIL] " + message); } private static void skip(String message) { skipped++; System.out.println(" [SKIP] " + message); } private static void hint(String text) { System.out.println(" Hint: " + text); } private static final int SECONDS = 10; private static volatile boolean timedOut = false; /** Runs one section; a missing method is a SKIP, a crash or a hang is a FAIL. */ private static void runSection(Runnable section) { final Throwable[] thrown = new Throwable[1]; Thread worker = new Thread(null, () -> { try { section.run(); } catch (Throwable e) { thrown[0] = e; } }, "section", 1 << 24); worker.setDaemon(true); worker.start(); try { worker.join(SECONDS * 1000L); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } Throwable e = thrown[0]; while (e instanceof InvocationTargetException || (e instanceof RuntimeException && e.getCause() instanceof InvocationTargetException)) { e = e instanceof InvocationTargetException ? e.getCause() : e.getCause().getCause(); } if (worker.isAlive()) { fail("this section did not finish in " + SECONDS + " seconds. Look for an infinite loop:" + "\n does every loop that walks a chain move on with node = node.next?"); timedOut = true; } else if (e instanceof UnsupportedOperationException) { skip(e.getMessage() + "; the rest of this section waits until you write it"); } else if (e instanceof StackOverflowError) { fail("this section stopped: StackOverflowError (methods calling each other forever)."); hint("resize calls put, and put calls resize when the table is too full. Did resize" + "\n set size back to 0 before putting the keys again? Otherwise the new table" + "\n looks full at once and grows again, and again."); } else if (e instanceof ArrayIndexOutOfBoundsException) { fail("this section stopped because your code threw " + e); if (String.valueOf(e.getMessage()).contains("-")) { hint("a negative bin index means hash returned a negative number: hashCode" + "\n can be negative, so hash uses Math.abs (Task 2)."); } else { hint("a bin index past the end of nodes. Does hash use capacity(), and does" + "\n resize make a new table with makeTable(newCapacity)?"); } } else if (e instanceof NullPointerException) { fail("this section stopped because your code threw " + e); hint("an empty bin, and the end of a chain, are null. Check that node != null" + "\n before reading node.key, node.value, or node.next."); } else if (e != null) { fail("this section stopped early because your code threw " + e); } } private static void section(String title, String what) { System.out.println(); System.out.println("== " + title + " =="); System.out.println(" " + what); } // ------------------------------------------------------------------ // Looking inside the table // ------------------------------------------------------------------ private static String fieldProblem = null; private static Object field(Object object, String name) { try { Field f = object.getClass().getDeclaredField(name); f.setAccessible(true); return f.get(object); } catch (ReflectiveOperationException e) { throw new IllegalStateException("can't read field " + name); } } private static Object[] table(HashMap map) { return (Object[]) field(map, "nodes"); } private static int sizeField(HashMap map) { return (Integer) field(map, "size"); } /** The bin a key belongs in, by the rule on the lab page. */ private static int bin(Object key, int capacity) { return Math.abs(key.hashCode() % capacity); } private static int callHash(HashMap map, String key) { try { Method m = HashMap.class.getDeclaredMethod("hash", Object.class); m.setAccessible(true); return (Integer) m.invoke(map, key); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (ReflectiveOperationException e) { throw new IllegalStateException("can't call hash(K key)"); } } /** The keys of bin i's chain, in order (stops at 100000 in case of a loop). */ private static ArrayList chain(HashMap map, int i) { ArrayList keys = new ArrayList<>(); Object node = table(map)[i]; while (node != null && keys.size() < 100000) { keys.add(field(node, "key")); node = field(node, "next"); } return keys; } /** Every node in the table, bin by bin. */ private static ArrayList nodes(HashMap map) { ArrayList all = new ArrayList<>(); for (Object node : table(map)) { int steps = 0; while (node != null && steps++ < 100000) { all.add(node); node = field(node, "next"); } } return all; } /** The keys of bin i, sorted, so the order of a chain doesn't matter. */ private static String binKeys(HashMap map, int i) { ArrayList keys = new ArrayList<>(); for (Object key : chain(map, i)) { keys.add("" + key); } Collections.sort(keys); return "" + keys; } /** Null if every node is in the bin its key hashes to, or else a description. */ private static String binProblem(HashMap map) { Object[] t = table(map); for (int i = 0; i < t.length; i++) { for (Object key : chain(map, i)) { int right = bin(key, t.length); if (right != i) { return "\"" + key + "\" is in bin " + i + ", but with " + t.length + " bins it belongs in bin " + right; } } } return null; } private static int longestChain(HashMap map) { int most = 0; for (int i = 0; i < table(map).length; i++) { most = Math.max(most, chain(map, i).size()); } return most; } private static Object valueOf(HashMap map, Object key) { for (Object node : nodes(map)) { if (field(node, "key").equals(key)) { return field(node, "value"); } } return null; } private static final String[] WORDS = {"dog", "bee", "fox", "ant", "cat", "eel", "gnu"}; private static final int[] NUMBERS = {15, 8, 17, 3, 10, 16, 20}; /** A table with 64 bins: it never grows in these small tests. */ private static HashMap roomy() { return new HashMap(64); } private static HashMap wordMap() { HashMap map = roomy(); for (int i = 0; i < WORDS.length; i++) { map.put(WORDS[i], NUMBERS[i]); } return map; } // ------------------------------------------------------------------ // Sections // ------------------------------------------------------------------ private static void providedSection() { section("Task 1: the provided HashMap", "Checks that the tester can look inside your table."); HashMap map = new HashMap(); try { table(map); sizeField(map); } catch (IllegalStateException e) { fieldProblem = "HashMap needs fields named nodes and size (as in the provided file)"; fail(fieldProblem); return; } checkEquals(16, map.capacity(), "new HashMap() starts with 16 bins"); checkEquals(10, new HashMap(10).capacity(), "new HashMap(10) starts with 10 bins"); HashMap small = new HashMap(4, 0.75); checkEquals(4, small.capacity(), "new HashMap(4, 0.75) starts with 4 bins"); check(nodes(small).isEmpty(), "every bin of a new map is empty (null)"); } private static void hashSection() { section("Task 2: hash", "Calls your hash(key) and checks it picks a bin from 0 to capacity() - 1."); HashMap four = new HashMap(4); HashMap sixteen = new HashMap(16); HashMap seven = new HashMap(7); checkEquals(0, callHash(four, "dog"), "\"dog\".hashCode() is 99644, and 99644 % 4 is 0, so with 4 bins dog goes in bin 0"); checkEquals(12, callHash(sixteen, "dog"), "99644 % 16 is 12, so with 16 bins dog goes in bin 12"); boolean ok = checkEquals(15, callHash(sixteen, "abroad"), "\"abroad\".hashCode() is NEGATIVE (-1423928639); -1423928639 % 16 is -15, so the bin is 15"); if (!ok) { hint("% keeps the sign of the hashCode. Math.abs makes the bin positive."); } ok = checkEquals(2, callHash(seven, "polygenelubricants"), "\"polygenelubricants\".hashCode() is the smallest int; with 7 bins the bin is 2"); if (!ok) { hint("use the line on the lab page: Math.abs(key.hashCode() % capacity()). Taking %" + "\n first matters: Math.abs can't make the smallest int positive."); } Random random = new Random(231); boolean inRange = true; boolean matches = true; int[] capacities = {7, 16, 100}; for (int capacity : capacities) { HashMap map = new HashMap(capacity); for (int i = 0; i < 3000; i++) { String word = Long.toString(random.nextLong(), 36); int h = callHash(map, word); if (h < 0 || h >= capacity) { inRange = false; } if (h != bin(word, capacity)) { matches = false; } } } check(inRange, "9,000 random words with 7, 16, and 100 bins: every bin is from 0 to capacity() - 1"); check(matches, "the same 9,000 words: hash follows the rule Math.abs(key.hashCode() % capacity())"); } private static void putSection() { section("Task 3: find, put, size, clear", "Puts words into a 64-bin table (big enough that it never grows)" + "\n and looks inside to check each one landed in the right bin."); HashMap map = roomy(); boolean allNull = true; for (int i = 0; i < WORDS.length; i++) { if (map.put(WORDS[i], NUMBERS[i]) != null) { allNull = false; } } check(allNull, "put returns null for each NEW word (there is no old value)"); checkEquals(7, nodes(map).size(), "7 puts of different words make 7 nodes in the table"); checkEquals(7, sizeField(map), "put adds 1 to size for each new word"); checkEquals(7, map.size(), "size() returns 7"); String where = binProblem(map); check(where == null, "each word is in the bin its hashCode gives" + (where == null ? "" : ":\n " + where)); HashMap clash = roomy(); clash.put("Aa", 1); clash.put("BB", 2); boolean chained = checkEquals("[Aa, BB]", binKeys(clash, 0), "\"Aa\" and \"BB\" have the SAME hashCode (2112), so both go in bin 0, in one chain"); if (!chained) { hint("a new node goes into its bin's chain: set the new node's next to the bin's" + "\n first node, then make the new node first. Setting nodes[i] without" + "\n linking next loses the words already in that bin."); } checkEquals(10, map.put("cat", 99), "put(\"cat\", 99): cat is already in the map, so put returns cat's OLD value, 10"); checkEquals(7, nodes(map).size(), "replacing cat's value adds no node"); checkEquals(7, map.size(), "replacing cat's value doesn't change size"); checkEquals(99, valueOf(map, "cat"), "cat's node now holds 99"); check(map.put("yak", null) == null && nodes(map).size() == 7, "put(\"yak\", null) does nothing: the map never stores a null value"); HashMap copies = roomy(); copies.put("cat", 1); copies.put(new String("cat"), 2); boolean same = nodes(copies).size() == 1; check(same, "\"cat\" put twice, as two different String objects, is ONE word"); if (!same) { hint("compare keys with node.key.equals(key), never ==. Two words read from a file" + "\n are different objects, so == says they differ."); } Random random = new Random(7); HashMap big = new HashMap(1024); TreeSet distinct = new TreeSet<>(); for (int i = 0; i < 300; i++) { int key = random.nextInt(2000) - 1000; big.put(key, i); distinct.add(key); } String bigWhere = binProblem(big); check(bigWhere == null && nodes(big).size() == distinct.size() && big.size() == distinct.size(), "300 random keys (some negative, some repeated): one node per different key, each in its right bin" + (bigWhere == null ? "" : ":\n " + bigWhere)); map.clear(); check(map.size() == 0 && nodes(map).isEmpty(), "after clear(), size is 0 and every bin is empty"); map.put("yak", 1); check(map.size() == 1 && nodes(map).size() == 1, "the map works again after clear()"); } private static void resizeSection() { section("Task 4: resize", "Puts lecture's 7 words into new HashMap(4, 0.75), which must grow" + "\n when size > 0.75 x capacity."); HashMap map = new HashMap(4, 0.75); int[] shouldBe = {4, 4, 4, 8, 8, 8, 16}; String[] why = { "1 word: 1 is not more than 0.75 x 4 = 3, so 4 bins", "2 words: still 4 bins", "3 words: 3 is not MORE than 3, so still 4 bins", "4 words: 4 > 3, so the table doubles to 8 bins", "5 words: 5 is not more than 0.75 x 8 = 6, so 8 bins", "6 words: 6 is not MORE than 6, so still 8 bins", "7 words: 7 > 6, so the table doubles to 16 bins"}; boolean steps = true; for (int i = 0; i < WORDS.length; i++) { map.put(WORDS[i], NUMBERS[i]); if (!checkEquals(shouldBe[i], map.capacity(), "put \"" + WORDS[i] + "\": " + why[i])) { steps = false; } } if (!steps && sizeField(map) > WORDS.length) { hint("size is " + sizeField(map) + " after only " + WORDS.length + " words. resize puts every" + "\n word again, and put adds 1 to size each time. Set size to 0 in resize" + "\n before putting the words into the new table."); } else if (!steps) { hint("grow when size > maxLoadFactor * capacity() (more than, not equal), and" + "\n double: resize(2 * capacity())."); } checkEquals(7, sizeField(map), "size is 7 after growing twice (growing doesn't add words)"); checkEquals(7, nodes(map).size(), "the 16-bin table holds exactly 7 nodes: none lost, none copied twice"); String where = binProblem(map); check(where == null, "every word moved to the bin its hashCode gives for 16 bins" + (where == null ? "" : ":\n " + where + "\n The bin depends on the capacity, so each word must be put again.")); boolean kept = true; for (int i = 0; i < WORDS.length; i++) { if (!Integer.valueOf(NUMBERS[i]).equals(valueOf(map, WORDS[i]))) { kept = false; } } check(kept, "every word kept its number while it moved"); HashMap lastYear = new HashMap(4, 0.75); lastYear.put(5, "1"); lastYear.put(100, "2"); lastYear.put(30, "3"); boolean before = lastYear.capacity() == 4 && binKeys(lastYear, 0).equals("[100]") && binKeys(lastYear, 1).equals("[5]") && binKeys(lastYear, 2).equals("[30]"); lastYear.put(12, "4"); lastYear.put(4, "5"); lastYear.put(6, "6"); boolean after = lastYear.capacity() == 8 && binKeys(lastYear, 4).equals("[100, 12, 4]") && binKeys(lastYear, 5).equals("[5]") && binKeys(lastYear, 6).equals("[30, 6]"); check(before && after, "keys 5, 100, 30 in 4 bins (bins 1, 0, 2); then 12, 4, 6 make it grow to 8 bins:" + "\n bin 4 holds 100, 12, 4; bin 5 holds 5; bin 6 holds 30, 6" + (before && after ? "" : "\n yours:\n" + lastYear)); Random random = new Random(1); HashMap big = new HashMap(4, 0.75); TreeSet distinct = new TreeSet<>(); for (int i = 0; i < 1000; i++) { int key = random.nextInt(5000); big.put(key, key * 2); distinct.add(key); } int capacity = 4; while (distinct.size() > 0.75 * capacity) { capacity *= 2; } checkEquals(capacity, big.capacity(), "1000 random puts (" + distinct.size() + " different keys) into new HashMap(4, 0.75): the table doubled just enough"); check(big.size() == distinct.size() && binProblem(big) == null, "every one of those keys is in its right bin, and size counts each once"); big.clear(); checkEquals(4, big.capacity(), "clear() after growing goes back to the starting capacity, 4"); } private static void getSection() { section("Task 5: get", "Looks up words, in a 64-bin table and after the table has grown."); HashMap empty = new HashMap(); checkEquals(null, empty.get("dog"), "get(\"dog\") on an empty map returns null"); HashMap map = wordMap(); boolean found = true; for (int i = 0; i < WORDS.length; i++) { if (!Integer.valueOf(NUMBERS[i]).equals(map.get(WORDS[i]))) { found = false; } } check(found, "get finds each of the 7 words with its number (dog 15, bee 8, ...)"); checkEquals(null, map.get("yak"), "get(\"yak\") returns null: yak is not in the map"); HashMap clash = roomy(); clash.put("Aa", 1); clash.put("BB", 2); check(Integer.valueOf(1).equals(clash.get("Aa")) && Integer.valueOf(2).equals(clash.get("BB")), "get finds both Aa and BB in their shared chain"); HashMap lone = roomy(); lone.put("BB", 2); checkEquals(null, lone.get("Aa"), "get(\"Aa\") when only \"BB\" is there returns null: same bin, but a different word"); checkEquals(15, map.get(new String("dog")), "get finds dog given as a different String object"); HashMap grown = new HashMap(4, 0.75); for (int i = 0; i < WORDS.length; i++) { grown.put(WORDS[i], NUMBERS[i]); } boolean all = true; for (int i = 0; i < WORDS.length; i++) { if (!Integer.valueOf(NUMBERS[i]).equals(grown.get(WORDS[i]))) { all = false; } } check(all, "after the table grows from 4 to 16 bins, get still finds all 7 words"); } private static void listSection() { section("Task 6: containsKey, keySet, values, maxDepth", "Asks about lecture's word map (64 bins) and others."); HashMap map = wordMap(); check(map.containsKey("eel"), "containsKey(\"eel\") is true"); check(!map.containsKey("yak"), "containsKey(\"yak\") is false"); ArrayList keys = map.keySet(); ArrayList values = map.values(); checkEquals("[ant, bee, cat, dog, eel, fox, gnu]", "" + new TreeSet(keys), "keySet holds each of the 7 words (in any order)"); checkEquals(7, keys.size(), "keySet has 7 entries: each word once"); boolean lined = values.size() == keys.size(); for (int i = 0; lined && i < keys.size(); i++) { if (!values.get(i).equals(valueOf(map, keys.get(i)))) { lined = false; } } check(lined, "values().get(i) is the value of keySet().get(i), for every i"); HashMap clash = roomy(); for (String word : new String[] {"Aa", "BB", "AaAa", "AaBB", "BBAa", "BBBB", "dog"}) { clash.put(word, 1); } boolean whole = checkEquals(7, clash.keySet().size(), "keySet of Aa, BB, AaAa, AaBB, BBAa, BBBB, dog (six share one bin) has all 7 words"); if (!whole) { hint("keySet and values must walk each bin's whole chain, not just its first node."); } HashMap empty = new HashMap(); check(empty.keySet().isEmpty() && empty.values().isEmpty(), "an empty map gives two empty lists"); checkEquals(0, empty.maxDepth(), "maxDepth of an empty map is 0: no chain at all"); checkEquals(6, clash.maxDepth(), "Aa, BB, AaAa, AaBB, BBAa, BBBB all land in bin 0 of 64 (dog elsewhere):" + "\n the biggest bin holds 6 items, so maxDepth is 6"); HashMap grown = new HashMap(4, 0.75); for (int i = 0; i < WORDS.length; i++) { grown.put(WORDS[i], NUMBERS[i]); } checkEquals(2, grown.maxDepth(), "lecture's 7 words in new HashMap(4, 0.75): dog and eel share bin 12, so maxDepth is 2"); Random random = new Random(3); HashMap big = new HashMap(); for (int i = 0; i < 1000; i++) { big.put(random.nextInt(100000), i); } checkEquals(longestChain(big), big.maxDepth(), "1000 random keys: maxDepth matches the biggest bin in the table"); } private static final String[] CHAIN = {"Aa", "BB", "AaAa"}; // all three hash to bin 0 of 64 private static HashMap chainMap() { HashMap map = roomy(); for (int i = 0; i < CHAIN.length; i++) { map.put(CHAIN[i], i + 1); } for (int i = 0; i < WORDS.length; i++) { map.put(WORDS[i], NUMBERS[i]); } return map; } private static void removeSection() { section("Task 7: remove", "Removes words from a 64-bin table with Aa, BB, AaAa chained in bin 0, plus" + "\n lecture's 7 words; then checks that the table shrinks when it gets too empty."); HashMap empty = new HashMap(); checkEquals(null, empty.remove("dog"), "remove(\"dog\") on an empty map returns null"); HashMap map = chainMap(); checkEquals(null, map.remove("yak"), "remove(\"yak\") returns null: yak is not in the map"); checkEquals(null, map.remove("BBBB"), "remove(\"BBBB\") returns null: bin 0 is busy, but BBBB isn't in it"); checkEquals(10, map.size(), "nothing was removed, so size is still 10"); String[] firsts = new String[3]; Object head = table(map)[0]; for (int i = 0; i < 3 && head != null; i++) { firsts[i] = "" + field(head, "key"); head = field(head, "next"); } String[] where = {"FIRST", "MIDDLE", "LAST"}; boolean cases = true; for (int i = 0; i < 3; i++) { HashMap fresh = chainMap(); String word = firsts[i]; int value = word.equals("Aa") ? 1 : word.equals("BB") ? 2 : 3; ArrayList rest = new ArrayList(); for (String w : CHAIN) { if (!w.equals(word)) { rest.add(w); } } Collections.sort(rest); boolean ok = checkEquals(value, fresh.remove(word), "remove(\"" + word + "\"), the " + where[i] + " node of bin 0's chain, returns its value, " + value) & checkEquals("" + rest, binKeys(fresh, 0), "after removing " + word + ", bin 0 holds " + rest) & checkEquals(9, fresh.size(), "remove subtracts 1 from size"); cases = cases && ok; } if (!cases) { hint("walk the chain with node and prev. If prev is null, the node is first:" + "\n nodes[i] = node.next. Otherwise prev.next = node.next."); } checkEquals(1, map.remove(new String("Aa")), "remove finds Aa given as a different String object"); check(map.get("Aa") == null && !map.containsKey("Aa"), "get and containsKey no longer find Aa"); checkEquals(null, map.remove("Aa"), "removing Aa a second time returns null"); Random random = new Random(231); HashMap yours = new HashMap(); TreeMap javas = new TreeMap(); String problem = null; for (int i = 0; i < 20000 && problem == null; i++) { int key = random.nextInt(600); if (random.nextInt(3) == 0) { Integer a = yours.remove(key); Integer b = javas.remove(key); if (a == null ? b != null : !a.equals(b)) { problem = "remove(" + key + ") returned " + a + ", should be " + b; } } else { yours.put(key, i); javas.put(key, i); } if (problem == null && yours.size() != javas.size()) { problem = "after operation " + (i + 1) + ", size is " + yours.size() + ", should be " + javas.size(); } } check(problem == null, "20,000 random puts and removes give the same answers as Java's own map" + (problem == null ? "" : ":\n " + problem)); HashMap shrink = new HashMap(4, 0.75); for (int i = 0; i < WORDS.length; i++) { shrink.put(WORDS[i], NUMBERS[i]); } int[] shouldBe = {16, 16, 16, 16, 8, 4, 4}; String[] why = { "6 words left: 6 is not less than 0.75 x 16 / 4 = 3, so 16 bins", "5 words left: still 16 bins", "4 words left: still 16 bins", "3 words left: 3 is not LESS than 3, so still 16 bins", "2 words left: 2 < 3, so the table halves to 8 bins", "1 word left: 1 < 0.75 x 8 / 4 = 1.5, so the table halves to 4 bins", "0 words left: 4 is the starting capacity, so the table never gets smaller than 4"}; boolean steps = true; for (int i = 0; i < WORDS.length; i++) { shrink.remove(WORDS[i]); if (!checkEquals(shouldBe[i], shrink.capacity(), "remove \"" + WORDS[i] + "\": " + why[i])) { steps = false; } } if (!steps) { hint("after a remove, if capacity() > the starting capacity and" + "\n size < maxLoadFactor * capacity() / 4, call resize(capacity() / 2)."); } HashMap bounds = new HashMap(4, 0.75); ArrayList keys = new ArrayList(); for (int i = 0; i < 2000; i++) { keys.add(i * 7919); bounds.put(i * 7919, i); } Collections.shuffle(keys, new Random(5)); problem = null; for (int i = 0; i < keys.size() && problem == null; i++) { Integer value = bounds.remove(keys.get(i)); int n = bounds.size(); int c = bounds.capacity(); if (value == null || value * 7919 != keys.get(i)) { problem = "remove(" + keys.get(i) + ") returned " + value; } else if (c > 4 && (n > 0.75 * c || n < 0.75 * c / 4)) { problem = "with " + n + " keys the table has " + c + " bins; it should keep" + "\n 0.75 x capacity / 4 <= size <= 0.75 x capacity"; } else if (c < 4) { problem = "the table shrank to " + c + " bins, below its starting 4"; } } check(problem == null, "2,000 keys put, then removed in random order: after every remove," + "\n f x C / 4 <= n <= f x C (unless the table is back at its starting capacity)" + (problem == null ? "" : ":\n " + problem)); check(bounds.size() == 0 && bounds.capacity() == 4 && binProblem(bounds) == null, "at the end the map is empty and back to 4 bins"); } public static void main(String[] args) { System.out.println("Lab 07 Tester"); runSection(Lab07Tester::providedSection); if (fieldProblem != null) { System.out.println("\n The tester can't look inside your table. Use the provided HashMap.java."); } else { Runnable[] sections = { Lab07Tester::hashSection, Lab07Tester::putSection, Lab07Tester::resizeSection, Lab07Tester::getSection, Lab07Tester::listSection, Lab07Tester::removeSection }; for (Runnable section : sections) { if (timedOut) { break; } runSection(section); } } if (timedOut) { System.out.println("\n Stopped after a section timed out; fix that first, then run again."); } System.out.println(); System.out.println("Summary: " + passed + " passed, " + failed + " failed, " + skipped + " skipped."); if (failed == 0 && skipped == 0) { System.out.println("All checks passed."); } else if (failed == 0) { System.out.println("No failures so far. SKIP means a method is not written yet."); } else { System.out.println("Fix the first FAIL above first; later failures are often caused by it."); } System.exit(failed == 0 ? 0 : 1); } }