Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 122:b006861cb795
add SearchQueryTest
author | one |
---|---|
date | Mon, 06 Oct 2014 22:42:03 +0900 |
parents | f783a27eed24 |
children | ef1173d93a45 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/PathNodeIterator.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/FjTreeMapTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/IndexTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/SearchQueryTest.java |
diffstat | 5 files changed, 122 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Thu Oct 02 17:24:25 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Mon Oct 06 22:42:03 2014 +0900 @@ -81,7 +81,7 @@ } public Iterator<Pair<TreeNode, NodePath>> find(final Query query) { - final PathNodeIterator itNode = new PathNodeIterator(node, query); + final PathNodeIterator itNode = new PathNodeIterator(node); return new Iterator<Pair<TreeNode, NodePath>>() {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/PathNodeIterator.java Thu Oct 02 17:24:25 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/PathNodeIterator.java Mon Oct 06 22:42:03 2014 +0900 @@ -25,7 +25,7 @@ * otherwise traverse tree and create index * * */ - public PathNodeIterator(TreeNode root, Query query) { + public PathNodeIterator(TreeNode root) { this.root = root; path = new DefaultNodePath(); node = root; @@ -79,7 +79,7 @@ searchStack.push(++childNumber); } } - System.out.println(path.toString()); + System.out.println("path = " + path.toString()); return new Pair<TreeNode, NodePath>(now, currentPath); }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/FjTreeMapTest.java Thu Oct 02 17:24:25 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/FjTreeMapTest.java Mon Oct 06 22:42:03 2014 +0900 @@ -1,27 +1,35 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.functionaljava; -import java.nio.ByteBuffer; + -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; - +import org.apache.commons.collections.map.StaticBucketMap; import org.junit.Assert; import org.junit.Test; +import fj.F; import fj.Ord; +import fj.data.List; +import fj.data.Option; import fj.data.TreeMap; -public class FjTreeMapTest { +public class FjTreeMapTest<A> { @Test public void testTreeMap() { + + List<Integer> list = List.nil(); + list = list.cons(1).cons(2).cons(3); + System.out.println(list.toString()); + list.length(); TreeMap<String,String> map = TreeMap.empty(Ord.stringOrd); TreeMap<String, String> newMap = map.set("name","tatsuki"); + Option<String> op = newMap.get("name"); + if (op.isNone()) { + + } + String str = op.some(); + TreeMap<String, String> newMap2 = map.set("name","kanagawa"); - String str = newMap.get("name").some(); String str2 = newMap2.get("name").some(); Assert.assertEquals(str,"tatsuki"); Assert.assertEquals(str2,"kanagawa");
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/IndexTest.java Thu Oct 02 17:24:25 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/IndexTest.java Mon Oct 06 22:42:03 2014 +0900 @@ -70,6 +70,7 @@ return parent; } + public void editIndex(TreeNode node, NodePath path, String attribute,String key) { Pair<TreeNode, NodePath> pair = new Pair<TreeNode, NodePath>(node, path);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/SearchQueryTest.java Mon Oct 06 22:42:03 2014 +0900 @@ -0,0 +1,101 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.query; + +import java.nio.ByteBuffer; +import java.security.KeyStore.Entry.Attribute; +import java.util.Iterator; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; + +import org.junit.Assert; +import org.junit.Test; + +public class SearchQueryTest { + + @Test + public void SearchQueryTest() { + Jungle jungle = new DefaultJungle(null, "hogehoge",new DefaultTreeEditor(new DefaultTraverser())); + jungle.createNewTree("tree"); + JungleTree tree = jungle.getTreeByName("tree"); + createTree(tree); + Iterator<Pair<TreeNode, NodePath>> searchNode = search(tree ,"<-1,0,1>",key); + while (searchNode.hasNext()){ + Assert.assertTrue(compare(searchNode.next().left(),"<-1,0,1>")); + } + } + + public Iterator<Pair<TreeNode, NodePath>> search(JungleTree tree ,String searchAttribute,String key){ + InterfaceTraverser ifTraverser = tree.getTraverser(); + return ifTraverser.find( + (TreeNode node) -> { + ByteBuffer attribute = node.getAttributes().get(key); + if(attribute != null){ + byte[] byteAttribute = attribute.array(); + String str = new String(byteAttribute); + System.out.println("attribute = " + str); + return str.equals(searchAttribute); + } + return false; + } + ); + } + + public boolean compare(TreeNode compareNode, String compareAttribute) { + String labName = compareNode.getAttributes().getString(key); + if (labName.equals(compareAttribute)) + return true; + return false; + } + + public static String key = "KEY"; + public static DefaultTreeNode factory = new DefaultTreeNode(); + + public void createTree(JungleTree tree) { + NodePath root = new DefaultNodePath(); + createChildren(tree, root, 0); + + for (int x = 0; x < 2; x++) { + createChildren(tree, root.add(0), x); + for (int y = 0; y < 2; y++) { + createChildren(tree, root.add(0).add(x), y); + } + } + + } + + public void createChildren(JungleTree tree, NodePath root, int num) { + JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 + Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root,num); // 新しく入れるところへのパス + if (either.isA()) { + Assert.fail(); + } + editor = either.b(); + either = editor.success(); + if (either.isA()) { + Assert.fail(); + } + NodePath childPath = root.add(num); + editor = tree.getTreeEditor(); + NodePath attribute = root.add(num); + System.out.println(attribute.toString()); + either = editor.putAttribute(childPath, key,ByteBuffer.wrap(attribute.toString().getBytes())); + if (either.isA()) { + Assert.fail(); + } + editor = either.b(); + either = editor.success(); + } +}