Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[COLLECTIONS 714] Add tests #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -427,6 +428,29 @@ public void testPrefixMapClearUsingRemove() {
assertEquals(Arrays.asList(2, 3, 7, 1), new ArrayList<>(trie.values()));
}

public void testNullTerminatedKey1() {
// COLLECTIONS-714
Map<String, Integer> map = new HashMap<>();
map.put("x", 0); // key of length 1
map.put("x\u0000", 1); // key of length 2
map.put("x\u0000y", 2); // key of length 3
Assert.assertEquals(3, map.size()); // 3 keys in map

PatriciaTrie<Integer> trie = new PatriciaTrie<>(map);
Assert.assertEquals(3, trie.size()); // 3 keys in corresponding trie
}

public void testNullTerminatedKey2() {
// COLLECTIONS-714
PatriciaTrie<Integer> trie = new PatriciaTrie<>();
trie.put("x", 0);
Assert.assertTrue(trie.containsKey("x")); // just inserted

trie.put("x\u0000", 1);
Assert.assertTrue(trie.containsKey("x\u0000")); // just inserted
Assert.assertTrue(trie.containsKey("x")); // previously inserted; not removed
}

//-----------------------------------------------------------------------

@Override
Expand Down