comparison src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/query/SearchQueryTest.java @ 144:0854f9a9e81d

change attrs form TreeMap<String , ByteBuffer> → TreeMap<String,List<ByteBuffer>>
author one
date Sun, 16 Nov 2014 06:40:48 +0900
parents afbe19c98f53
children a2c374a2686b
comparison
equal deleted inserted replaced
143:afbe19c98f53 144:0854f9a9e81d
25 import fj.data.Option; 25 import fj.data.Option;
26 import fj.data.TreeMap; 26 import fj.data.TreeMap;
27 27
28 public class SearchQueryTest { 28 public class SearchQueryTest {
29 29
30 @Test 30 @Test
31 public void SearchQueryTest() { 31 public void SearchQueryTest() {
32 Jungle jungle = new DefaultJungle(null, "hogehoge",new DefaultTreeEditor(new DefaultTraverser())); 32 Jungle jungle = new DefaultJungle(null, "hogehoge",new DefaultTreeEditor(new DefaultTraverser()));
33 jungle.createNewTree("tree"); 33 jungle.createNewTree("tree");
34 JungleTree tree = jungle.getTreeByName("tree"); 34 JungleTree tree = jungle.getTreeByName("tree");
35 createTree(tree); 35 createTree(tree);
38 TreeMap<String, TreeMap<String, List< NodePath>>> cheackIndex = ifTraverser.getIndex(); 38 TreeMap<String, TreeMap<String, List< NodePath>>> cheackIndex = ifTraverser.getIndex();
39 Assert.assertTrue(cheackIndex.isEmpty()); 39 Assert.assertTrue(cheackIndex.isEmpty());
40 40
41 Iterator<Pair<TreeNode, NodePath>> searchNode = ifTraverser.find( 41 Iterator<Pair<TreeNode, NodePath>> searchNode = ifTraverser.find(
42 (TreeNode node) -> { 42 (TreeNode node) -> {
43 ByteBuffer attribute = node.getAttributes().get(key); 43 List<ByteBuffer> attributeList = node.getAttributes().get(key);
44 if(attribute != null){ 44 if(attributeList.isNotEmpty()){
45 for (ByteBuffer attribute : attributeList) {
45 byte[] byteAttribute = attribute.array(); 46 byte[] byteAttribute = attribute.array();
46 String str = new String(byteAttribute); 47 String str = new String(byteAttribute);
47 System.out.println("attribute = " + str); 48 System.out.println("attribute = " + str);
48 return str.equals("<-1,0,1>"); 49 if (str.equals("<-1,0,1>"))
50 return true;
51 continue;
52 }
49 } 53 }
50 return false; 54 return false;
51 } 55 }
52 ,key,"<-1,0,1>"); 56 ,key,"<-1,0,1>");
53 57
54 58
55 while (searchNode.hasNext()){ 59 while (searchNode.hasNext()){
56 Assert.assertTrue(compare(searchNode.next().left(),"<-1,0,1>")); 60 TreeNode node = searchNode.next().left();
61 Assert.assertTrue(compare(node,"<-1,0,1>"));
57 } 62 }
58 63
59 TreeMap<String, TreeMap<String, List<NodePath>>> index = ifTraverser.getIndex(); 64 TreeMap<String, TreeMap<String, List<NodePath>>> index = ifTraverser.getIndex();
60 Option<TreeMap<String, List<NodePath>>> opIndex = index.get(key); 65 Option<TreeMap<String, List<NodePath>>> opIndex = index.get(key);
61 Assert.assertTrue(!opIndex.isNone()); 66 Assert.assertTrue(!opIndex.isNone());
62 TreeMap<String, List<NodePath>> innerIndex = opIndex.some(); 67 TreeMap<String, List<NodePath>> innerIndex = opIndex.some();
63 Assert.assertTrue(!innerIndex.get("<-1,0,0>").isNone()); 68 Assert.assertTrue(!innerIndex.get("<-1,0,0>").isNone());
64 } 69 }
65
66
67 public boolean compare(TreeNode compareNode, String compareAttribute) {
68 String labName = compareNode.getAttributes().getString(key);
69 if (labName.equals(compareAttribute))
70 return true;
71 return false;
72 }
73 70
74 public static String key = "KEY"; 71 public boolean compare(TreeNode compareNode, String compareAttribute) {
75 public static DefaultTreeNode factory = new DefaultTreeNode(); 72 Iterator<String> labNameIterator = compareNode.getAttributes().getString(key);
73 Assert.assertTrue(labNameIterator.hasNext());
74 String labName = labNameIterator.next();
75 if (labName.equals(compareAttribute))
76 return true;
77 return false;
78 }
76 79
77 public void createTree(JungleTree tree) { 80 public static String key = "KEY";
78 NodePath root = new DefaultNodePath(); 81 public static DefaultTreeNode factory = new DefaultTreeNode();
79 createChildren(tree, root, 0);
80 82
81 for (int x = 0; x < 2; x++) { 83 public void createTree(JungleTree tree) {
82 createChildren(tree, root.add(0), x); 84 NodePath root = new DefaultNodePath();
83 for (int y = 0; y < 2; y++) { 85 createChildren(tree, root, 0);
84 createChildren(tree, root.add(0).add(x), y);
85 }
86 }
87 86
88 } 87 for (int x = 0; x < 2; x++) {
88 createChildren(tree, root.add(0), x);
89 for (int y = 0; y < 2; y++) {
90 createChildren(tree, root.add(0).add(x), y);
91 }
92 }
89 93
90 public void createChildren(JungleTree tree, NodePath root, int num) { 94 }
91 JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 95
92 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root,num); // 新しく入れるところへのパス 96 public void createChildren(JungleTree tree, NodePath root, int num) {
93 if (either.isA()) { 97 JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成
94 Assert.fail(); 98 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root, num); // 新しく入れるところへのパス
95 } 99 if (either.isA()) {
96 editor = either.b(); 100 Assert.fail();
97 either = editor.success(); 101 }
98 if (either.isA()) { 102 editor = either.b();
99 Assert.fail(); 103 either = editor.success();
100 } 104 if (either.isA()) {
101 NodePath childPath = root.add(num); 105 Assert.fail();
102 editor = tree.getTreeEditor(); 106 }
103 NodePath attribute = root.add(num); 107 NodePath childPath = root.add(num);
104 System.out.println(attribute.toString()); 108 editor = tree.getTreeEditor();
105 either = editor.putAttribute(childPath, key,ByteBuffer.wrap(attribute.toString().getBytes())); 109 NodePath attribute = root.add(num);
106 if (either.isA()) { 110 System.out.println(attribute.toString());
107 Assert.fail(); 111 either = editor.putAttribute(childPath, key, ByteBuffer.wrap(attribute.toString().getBytes()));
108 } 112 if (either.isA()) {
109 editor = either.b(); 113 Assert.fail();
110 either = editor.success(); 114 }
111 } 115 editor = either.b();
116 either = editor.success();
117 }
112 } 118 }