moar unit tests and documentation

This commit is contained in:
Vincent Batts 2012-11-01 13:16:32 -04:00
parent dcc9c50655
commit 90b8b201db
3 changed files with 76 additions and 4 deletions

View File

@ -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++;
}

View File

@ -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);
}
}

View File

@ -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));
}
}