diff --git a/src/main/java/com/redhat/trie/NodeContext.java b/src/main/java/com/redhat/trie/NodeContext.java index 3ac8d89..659ff38 100644 --- a/src/main/java/com/redhat/trie/NodeContext.java +++ b/src/main/java/com/redhat/trie/NodeContext.java @@ -22,17 +22,35 @@ package com.redhat.trie; public class NodeContext { private long nodeId = 0; + /** + * Constructs with an id of 0 + */ public NodeContext() { } + /** + * Constructs with provided startId + * + * @param startId long of the id to start at + */ public NodeContext(long startId) { this.nodeId = startId; } + /** + * current context id + * + * @return long of current id position + */ public long getId() { return this.nodeId; } + /** + * get current context id, and increment the id + * + * @return long of current id position + */ public long nextId() { return this.nodeId++; } diff --git a/src/test/java/com/redhat/trie/TestHuffNode.java b/src/test/java/com/redhat/trie/TestHuffNode.java index 55f3215..c153103 100644 --- a/src/test/java/com/redhat/trie/TestHuffNode.java +++ b/src/test/java/com/redhat/trie/TestHuffNode.java @@ -3,16 +3,69 @@ package com.redhat.trie; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import org.junit.Test; public class TestHuffNode { @Test - public void testNew(){ - HuffNode hn = new HuffNode(new Object(), 1); + public void testNew0(){ + HuffNode hn = new HuffNode(new Object(), 0); assertNotNull(hn); } + + @Test + public void testNew1(){ + HuffNode hn = new HuffNode(new NodeContext(), new Object(), 0); + assertNotNull(hn); + } + + @Test + public void testNew2(){ + HuffNode hn = new HuffNode(new Object(), + 0, + new HuffNode(new Object(), 1), + new HuffNode(new Object(), 2)); + assertNotNull(hn); + } + + @Test + public void testNew3(){ + HuffNode hn = new HuffNode(new NodeContext(), + new Object(), + 0, + new HuffNode(new Object(), 1), + new HuffNode(new Object(), 2)); + assertNotNull(hn); + } + + @Test + public void testWeight(){ + HuffNode hn = new HuffNode(new Object(), + 1, + new HuffNode(new Object(), 2), + new HuffNode(new Object(), 3)); + assertEquals(hn.getWeight(), 1); + assertEquals(hn.getLeft().getWeight(), 2); + assertEquals(hn.getRight().getWeight(), 3); + } + + @Test + public void testValue(){ + HuffNode hn = new HuffNode(new Object(), 1); + assertTrue(hn.getValue() instanceof Object); + } + + @Test + public void testCtx(){ + NodeContext ctx = new NodeContext(0); + HuffNode hn = new HuffNode(ctx, new Object(), 0); + assertEquals(hn.getContext(), ctx); + + // it's +1 because the HuffNode will have run ctx.nextId() + assertEquals(hn.getContext().getId(), 1); + } } diff --git a/src/test/java/com/redhat/trie/TestNodeContext.java b/src/test/java/com/redhat/trie/TestNodeContext.java index f32b217..8fedc8d 100644 --- a/src/test/java/com/redhat/trie/TestNodeContext.java +++ b/src/test/java/com/redhat/trie/TestNodeContext.java @@ -17,6 +17,7 @@ public class TestNodeContext { public void testNew2() { NodeContext nc = new NodeContext(1); assertNotNull(nc); + assertEquals(nc.getId(), 1); } @Test @@ -24,9 +25,9 @@ public class TestNodeContext { NodeContext nc = new NodeContext(); assertEquals(nc.getId(), 0); - long next = nc.nextId(); + long curr = nc.nextId(); assertEquals(nc.getId(), 1); - assertEquals(nc.getId(), (next + 1)); + assertEquals(nc.getId(), (curr + 1)); } }