diff --git a/src/cse332/datastructures/containers/Item.java b/src/cse332/datastructures/containers/Item.java index 83d6867480fd246657a879215bf6238c85e4599b..a6fc7fca243c4c4365256ffd6e72b48f6beee0eb 100644 --- a/src/cse332/datastructures/containers/Item.java +++ b/src/cse332/datastructures/containers/Item.java @@ -1,5 +1,7 @@ package cse332.datastructures.containers; +import java.util.Objects; + /** * Simple class to hold a piece of data and its value. * @@ -40,4 +42,18 @@ public class Item<K, V> { public String toString() { return this.key + "=" + this.value + ""; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Item<?, ?> item = (Item<?, ?>) o; + return Objects.equals(key, item.key) && + Objects.equals(value, item.value); + } + + @Override + public int hashCode() { + return Objects.hash(key, value); + } } diff --git a/src/tests/gitlab/ckpt1/NGramToNextChoicesMapTests.java b/src/tests/gitlab/ckpt1/NGramToNextChoicesMapTests.java index 3ef3d986875400d25d8807f246084b12e2ae835f..a82e790d67497ce5f32edb4f04c3058d1e0651a8 100644 --- a/src/tests/gitlab/ckpt1/NGramToNextChoicesMapTests.java +++ b/src/tests/gitlab/ckpt1/NGramToNextChoicesMapTests.java @@ -16,14 +16,8 @@ import org.junit.Test; import static org.junit.Assert.*; public class NGramToNextChoicesMapTests { - private Supplier<Dictionary<NGram, Dictionary<AlphabeticString, Integer>>> newOuter = - () -> new BinarySearchTree(); - - private Supplier<Dictionary<AlphabeticString, Integer>> newInner = - () -> new BinarySearchTree(); - private NGramToNextChoicesMap init() { - return new NGramToNextChoicesMap(newOuter, newInner); + return new NGramToNextChoicesMap(BinarySearchTree::new, BinarySearchTree::new); } @Test(timeout = 3000) @@ -172,13 +166,7 @@ public class NGramToNextChoicesMapTests { Arrays.sort(results, Comparator.comparing(r -> r.key)); Item<String, Integer>[] expected = answers.get(ngram); // checks for correct number of unique words after - assertEquals(expected.length, results.length); - for (int j = 0; j < expected.length; j++) { - // checks if correct word after via sorted words - assertEquals(expected[j].key, results[j].key); - // checks if correct count for given word after - assertEquals(expected[j].value, results[j].value); - } + assertArrayEquals(expected, results); } } }