Mercurial > hg > Members > shoshi > TreeCMSv2
view src/treecms/test/TreeTest.java @ 6:12604eb6b615
added javadoc
author | shoshi |
---|---|
date | Mon, 14 Mar 2011 23:24:38 +0900 |
parents | 87bba22e4fa2 |
children |
line wrap: on
line source
package treecms.test; import java.util.LinkedList; import junit.framework.Assert; import org.junit.Test; import treecms.api.Node; import treecms.api.NodeData; import treecms.api.Tree; public class TreeTest { Tree m_tree; public TreeTest(Tree _tree) { m_tree = _tree; } @Test public void testUpdateTree() { Node ch1 = m_tree.getForest().create(); Node ch2 = m_tree.getForest().create(); Node ch11 = m_tree.getForest().create(); Node ch12 = m_tree.getForest().create(); LinkedList<Node> list = new LinkedList<Node>(); list.add(ch1); list.add(ch2); m_tree.getRoot().getData().add(list); LinkedList<Node> ch1list = new LinkedList<Node>(); ch1list.add(ch11); ch1.getData().add(ch1list); LinkedList<Node> ch2list = new LinkedList<Node>(); ch2list.add(ch12); ch2.getData().add(ch2list); LinkedList<Node> before = findPath(m_tree.getRoot(),ch11); NodeData newData = ch11.getData().deepCopy(); m_tree.updateTree(ch11,newData); LinkedList<Node> after = findPath(m_tree.getRoot(),ch11); for(int i = 0;i < before.size();i ++){ boolean result = before.get(i).getID().isFamily(after.get(i).getID()); Assert.assertEquals(true,result); } } public LinkedList<Node> findPath(Node _from,Node _target) { if(_from.getID().isFamily(_target.getID())){ LinkedList<Node> path = new LinkedList<Node>(); path.add(_from); return path; } for(Node child : _from.getData().list()){ LinkedList<Node> path = findPath(child,_target); if(path != null){ path.add(_from); } } return null; } }