42 lines
1.6 KiB
Java
42 lines
1.6 KiB
Java
import lostcave.deathchests.util.LookUpTable;
|
|
import lostcave.deathchests.util.LookUpTable.DuplicateKeyException;
|
|
|
|
public class TestLUT {
|
|
public static void main(String[] args) {
|
|
System.out.println("Testing LookUpTable...");
|
|
|
|
LookUpTable<Integer> table = new LookUpTable<>();
|
|
|
|
table.add("one", 1);
|
|
table.add("two", 2);
|
|
table.add("three", 3);
|
|
|
|
if (table.get("one") != 1 || table.get("two") != 2 || table.get("three") != 3) System.err.println("Failed add test.");
|
|
else System.out.println("Passed add test.");
|
|
|
|
if (table.getKey(1).equals("two")) System.out.println("Passed getKey test (1/2).");
|
|
else System.err.println("Failed getKey test (1/2).");
|
|
|
|
table.remove("two");
|
|
if (table.get("two") == null) System.out.println("Passed remove test.");
|
|
else System.err.println("Failed remove test");
|
|
|
|
if (table.getKey(1).equals("three")) System.out.println("Passed getKey test (2/2).");
|
|
else System.err.println("Failed getKey test (2/2): " + table.getKey(1));
|
|
|
|
if (table.storedElements()==2) System.out.println("Passes storedElements test.");
|
|
else System.out.println("Failed storedElements test.");
|
|
|
|
table.set("three", 33);
|
|
if (table.get("three")==33) System.out.println("Passed set test.");
|
|
else System.out.println("Failed set test.");
|
|
|
|
try {
|
|
table.add("three", 2);
|
|
System.err.println("Failed duplicate key test.");
|
|
} catch (DuplicateKeyException e) {
|
|
System.out.println("Passed duplicate key test.");
|
|
}
|
|
}
|
|
}
|