Skip to content
Snippets Groups Projects
Commit 85790ef2 authored by Nathan Lipiarski's avatar Nathan Lipiarski
Browse files

Adding equals to item for better testing abilities

parent acafcc06
No related branches found
No related tags found
No related merge requests found
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);
}
}
......@@ -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);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment