From 8fdeec331c424f2a7cfc98619e98a0d2420ddf7c Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Sun, 10 Mar 2019 22:15:07 -0500 Subject: Hash chain simulation done! Created test cases for the hash function. Tested the code by running the main function without writting test cases. I wish the starter code was written in a way that facilitated testing... --- src/test/HashChainsTest.java | 19 +++++++++++++++++++ src/test/PhoneBookTest.java | 26 -------------------------- 2 files changed, 19 insertions(+), 26 deletions(-) create mode 100644 src/test/HashChainsTest.java delete mode 100644 src/test/PhoneBookTest.java (limited to 'src/test') diff --git a/src/test/HashChainsTest.java b/src/test/HashChainsTest.java new file mode 100644 index 0000000..9a7f192 --- /dev/null +++ b/src/test/HashChainsTest.java @@ -0,0 +1,19 @@ +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class HashChainsTest { + @Test + void test(){ + HashChains hc = new HashChains(); + hc.bucketCount = 5; + assertEquals(4, hc.hashFunc("world")); + assertEquals(4, hc.hashFunc("HellO")); + assertEquals(2, hc.hashFunc("GooD")); + assertEquals(2, hc.hashFunc("luck")); + + hc.bucketCount = 3; + assertEquals(1, hc.hashFunc("add")); + assertEquals(1, hc.hashFunc("help")); + } +} \ No newline at end of file diff --git a/src/test/PhoneBookTest.java b/src/test/PhoneBookTest.java deleted file mode 100644 index fb898f0..0000000 --- a/src/test/PhoneBookTest.java +++ /dev/null @@ -1,26 +0,0 @@ -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class PhoneBookTest { - @Test - void test() { - PhoneBook.add(911, "police"); - PhoneBook.add(76213, "Mom"); - PhoneBook.add(17239, "Bob"); - - assertEquals("Mom", PhoneBook.find(76213)); - assertEquals("not found", PhoneBook.find(910)); - assertEquals("police", PhoneBook.find(911)); - - PhoneBook.del(910); - PhoneBook.del(911); - - assertEquals("not found", PhoneBook.find(911)); - assertEquals("Mom", PhoneBook.find(76213)); - - PhoneBook.add(76213, "daddy"); - assertEquals("daddy", PhoneBook.find(76213)); - } - -} \ No newline at end of file -- cgit v1.2.3