From 6798fd7744dc6ae1717bf9d217d141c0923d0290 Mon Sep 17 00:00:00 2001 From: jbolcer Date: Mon, 19 May 2025 11:50:13 -0700 Subject: [PATCH 1/2] Add JUnit tests for IntDict.java --- core/test/processing/data/IntDictTest.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 core/test/processing/data/IntDictTest.java diff --git a/core/test/processing/data/IntDictTest.java b/core/test/processing/data/IntDictTest.java new file mode 100644 index 0000000000..eb68bdb129 --- /dev/null +++ b/core/test/processing/data/IntDictTest.java @@ -0,0 +1,4 @@ +package processing.data; + +public class IntDictTest { +} From ad24310cd89bf63e56386fba697e51384c810512 Mon Sep 17 00:00:00 2001 From: jbolcer Date: Mon, 19 May 2025 11:53:46 -0700 Subject: [PATCH 2/2] Complete IntDictTest.java with full test coverage --- core/test/processing/data/IntDictTest.java | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/core/test/processing/data/IntDictTest.java b/core/test/processing/data/IntDictTest.java index eb68bdb129..b2a91a5f8f 100644 --- a/core/test/processing/data/IntDictTest.java +++ b/core/test/processing/data/IntDictTest.java @@ -1,4 +1,150 @@ package processing.data; +import org.junit.Before; +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.StringReader; + +import static org.junit.Assert.*; + public class IntDictTest { + + private IntDict intDict; + + @Before + public void setUp() { + intDict = new IntDict(); + } + + @Test + public void testDefaultConstructor() { + assertEquals(0, intDict.size()); + } + + @Test + public void testAddAndGet() { + intDict.set("key1", 5); + intDict.set("key2", 10); + assertEquals(5, intDict.get("key1")); + assertEquals(10, intDict.get("key2")); + } + + @Test + public void testHasKey() { + intDict.set("key1", 5); + assertTrue(intDict.hasKey("key1")); + assertFalse(intDict.hasKey("key3")); + } + + @Test + public void testRemove() { + intDict.set("key1", 5); + intDict.set("key2", 10); + + assertEquals(5, intDict.remove("key1")); + assertFalse(intDict.hasKey("key1")); + assertEquals(10, intDict.get("key2")); + } + + @Test + public void testMinAndMax() { + intDict.set("key1", 5); + intDict.set("key2", 15); + intDict.set("key3", 10); + + assertEquals("key1", intDict.minKey()); + assertEquals("key2", intDict.maxKey()); + assertEquals(5, intDict.minValue()); + assertEquals(15, intDict.maxValue()); + } + + @Test + public void testResize() { + intDict.set("key1", 5); + intDict.set("key2", 10); + intDict.set("key3", 15); + + intDict.resize(2); + assertEquals(2, intDict.size()); + assertTrue(intDict.hasKey("key1")); + assertTrue(intDict.hasKey("key2")); + assertFalse(intDict.hasKey("key3")); + } + + @Test + public void testIncrementFunctionality() { + intDict.set("key1", 1); + intDict.increment("key1"); + assertEquals(2, intDict.get("key1")); + + intDict.increment(intDict); // Merging the intDict into itself + assertEquals(4, intDict.get("key1")); + } + + @Test + public void testSortValues() { + intDict.set("key1", 40); + intDict.set("key2", 10); + intDict.set("key3", 20); + + intDict.sortValues(); + + assertEquals("key2", intDict.key(0)); + assertEquals("key3", intDict.key(1)); + assertEquals("key1", intDict.key(2)); + } + + @Test + public void testSortKeys() { + intDict.set("bKey", 40); + intDict.set("aKey", 10); + intDict.set("cKey", 20); + + intDict.sortKeys(); + + assertEquals("aKey", intDict.key(0)); + assertEquals("bKey", intDict.key(1)); + assertEquals("cKey", intDict.key(2)); + } + + @Test + public void testBufferedReaderConstructor() { + String data = "key1\t100\nkey2\t200"; + BufferedReader reader = new BufferedReader(new StringReader(data)); + IntDict intDictFromReader = new IntDict(reader); + + assertEquals(2, intDictFromReader.size()); + assertEquals(100, intDictFromReader.get("key1")); + assertEquals(200, intDictFromReader.get("key2")); + } + + @Test + public void testCloneFunctionality() { + intDict.set("key1", 1); + intDict.set("key2", 2); + + IntDict cloned = intDict.copy(); + + assertEquals(2, cloned.size()); + assertEquals(1, cloned.get("key1")); + assertEquals(2, cloned.get("key2")); + } + + @Test + public void testDivision() { + intDict.set("key1", 10); + intDict.div("key1", 2); + assertEquals(5, intDict.get("key1")); + } + + @Test + public void testToJSON() { + intDict.set("key1", 5); + intDict.set("key2", 10); + + String json = intDict.toJSON(); + assertTrue(json.contains("\"key1\": 5")); + assertTrue(json.contains("\"key2\": 10")); + } }