Mercurial > hg > Members > tatsuki > bench > jungle-core
view src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/treeeditor/TreeNodeChildrenTest.java @ 54:650fe2a0dccc
modified tests
author | Shoshi TAMAKI |
---|---|
date | Fri, 08 Feb 2013 17:08:42 +0900 |
parents | src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/treeeditor/ClonableChildrenTest.java@ed6737db637a |
children | 26dfa90016d1 |
line wrap: on
line source
package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.treeeditor; import java.nio.ByteBuffer; import org.junit.Assert; import fj.data.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import junit.framework.TestCase; public abstract class TreeNodeChildrenTest<T extends TreeNode<T>> extends TestCase { public abstract TreeNode<T> instance(); public void testAddNewChildAtWithNode() { int count = 5; for(Integer pos : List.range(0,5)){ _testAddNewChildAtWithNode(count,pos); } } public void _testAddNewChildAtWithNode(int _count,int _pos) { TreeNode<T> instance = instance(); Either<Error, T> either; for(int i = 0;i < _count;i ++){ either = instance.getChildren().addNewChildAt(0); if(either.isA()){ Assert.fail(); } instance = either.b(); } T newNode = instance.createNewNode(); String key = "KEY"; ByteBuffer value = ByteBuffer.wrap("VALUE".getBytes()); either = newNode.getAttributes().put(key,value); if(either.isA()){ Assert.fail(); } newNode = either.b(); either = instance.getChildren().addNewChildAt(_pos,newNode); if(either.isA()){ Assert.fail(); } instance = either.b(); // check either = instance.getChildren().at(_pos); if(either.isA()){ Assert.fail(); } T checkTarget = either.b(); ByteBuffer actual = checkTarget.getAttributes().get(key); Assert.assertEquals(0,value.compareTo(actual)); } public void testReplaceAt() { int count = 5; for(Integer pos : List.range(0,count)){ _testReplaceAt(count,pos); } } public void _testReplaceAt(int _count,int _pos) { TreeNode<T> instance = instance(); String key = "KEY"; ByteBuffer value = ByteBuffer.wrap("VALUE".getBytes()); // prepare for(int i = 0;i < _count;i ++){ T newNode = instance.createNewNode(); Either<Error,T> either = newNode.getAttributes().put(key,value); if(either.isA()){ Assert.fail("failed to put attributes to child"); } newNode = either.b(); either = instance.getChildren().addNewChildAt(0,newNode); if(either.isA()){ Assert.fail("failed to add child to instance"); } instance = either.b(); } int size = instance.getChildren().size(); Assert.assertEquals(_count,size); // create node for replacement. ByteBuffer replaceNodeValue = ByteBuffer.wrap("EULAV".getBytes()); T replacement = instance.createNewNode(); Either<Error,T> either = replacement.getAttributes().put(key,replaceNodeValue); if(either.isA()){ Assert.fail("failed to create replacement node"); } replacement = either.b(); // replace either = instance.getChildren().replaceNode(_pos,replacement); if(either.isA()){ Assert.fail("failed to replace node."); } instance = either.b(); TreeNodeChildren<T> children = instance.getChildren(); for(Integer pos : List.range(0,_count)){ either = children.at(pos.intValue()); if(either.isA()){ Assert.fail("failed to get node."); } T ch = either.b(); ByteBuffer expect = (_pos != pos) ? value : replaceNodeValue; ByteBuffer actual = ch.getAttributes().get(key); Assert.assertEquals(0,expect.compareTo(actual)); } } }