Skip to content

Commit

Permalink
Add test cases for TriNode
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoyun committed Mar 19, 2024
1 parent cca24d9 commit fccdf65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/commons/util/TrieNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public int hashCode() {

@Override
public String toString() {
return String.format("TrieNode: %s", this.character);
return String.format("TrieNode: %s%s",
this.character,
this.isEndOfWord ? "\0" : ""
);
}
}
22 changes: 22 additions & 0 deletions src/test/java/seedu/address/commons/util/TrieNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,33 @@ void getChildren() {
@Test
void testEquals() {
TrieNode trieNode = new TrieNode('a');

assertEquals(trieNode, trieNode);
assertNotEquals(trieNode, null);
assertNotEquals(trieNode, "a");

TrieNode trieNode2 = new TrieNode('a');

assertEquals(trieNode, trieNode2);

trieNode.setEndOfWord(true);
assertNotEquals(trieNode, trieNode2);
}

@Test
void testHashCode() {
TrieNode trieNode = new TrieNode('a');
TrieNode trieNode2 = new TrieNode('a');

assertEquals(trieNode.hashCode(), trieNode2.hashCode());
}

@Test
void testToString() {
TrieNode trieNode = new TrieNode('a');
assertEquals("TrieNode: a", trieNode.toString());

trieNode.setEndOfWord(true);
assertEquals("TrieNode: a\0", trieNode.toString());
}
}

0 comments on commit fccdf65

Please sign in to comment.