view src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/TreeNodeChildrenTest.java @ 0:44465893e8b8

first Commit
author Kazuma
date Wed, 30 Nov 2016 01:47:55 +0900
parents
children
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 TreeNode;
import TreeNodeChildren;
import Either;
import 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();
		}
		
		TreeNode<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 ++){
			TreeNode<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());
		TreeNode<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));
		}
	}
}*/