Mercurial > hg > Members > tatsuki > bench > jungle-core
comparison src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/IndexCommitTest.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 |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.index; | 1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.index; |
2 | |
3 | |
4 | 2 |
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; | 3 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; |
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; | 4 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; | 5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; | 6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; |
17 import junit.framework.Assert; | 15 import junit.framework.Assert; |
18 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | 16 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; |
19 | 17 |
20 import java.nio.ByteBuffer; | 18 import java.nio.ByteBuffer; |
21 | 19 |
22 | |
23 import org.junit.Test; | 20 import org.junit.Test; |
24 | 21 |
25 import fj.data.List; | 22 import fj.data.List; |
26 import fj.data.Option; | 23 import fj.data.Option; |
27 import fj.data.TreeMap; | 24 import fj.data.TreeMap; |
28 | 25 |
29 public class IndexCommitTest { | 26 public class IndexCommitTest { |
30 | 27 |
31 @Test | 28 @Test |
32 public void IndexCommitTest() throws InterruptedException { | 29 public void IndexCommitTest() throws InterruptedException { |
33 | |
34 Jungle jungle = new DefaultJungle(null, "hogehoge",new DefaultTreeEditor(new DefaultTraverser())); | |
35 jungle.createNewTree("tree"); | |
36 JungleTree tree = jungle.getTreeByName("tree"); | |
37 createTree(tree); | |
38 tree.getRootNode(); | |
39 InterfaceTraverser ifTraverser = tree.getTraverser(); | |
40 | 30 |
41 ifTraverser.find((TreeNode node) -> { | 31 Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor(new DefaultTraverser())); |
42 ByteBuffer attribute = node.getAttributes().get(key); | 32 jungle.createNewTree("tree"); |
43 if (attribute != null) { | 33 JungleTree tree = jungle.getTreeByName("tree"); |
44 byte[] byteAttribute = attribute.array(); | 34 createTree(tree); |
45 String str = new String(byteAttribute); | 35 tree.getRootNode(); |
46 System.out.println("attribute = " + str); | 36 InterfaceTraverser ifTraverser = tree.getTraverser(); |
47 return str.equals("<-1,0,1>"); | |
48 } | |
49 return false; | |
50 }, key, "<-1,0,1>"); | |
51 | 37 |
52 //check index | 38 ifTraverser.find((TreeNode node) -> { |
53 TreeMap<String, TreeMap<String, List<NodePath>>> index = ifTraverser.getIndex(); | 39 List<ByteBuffer> attributeList = node.getAttributes().get(key); |
54 Option<TreeMap<String, List<NodePath>>> opIndex = index.get(key); | 40 if (attributeList.isNotEmpty()) { |
55 | 41 for (ByteBuffer attribute : attributeList) { |
56 Assert.assertTrue(!opIndex.isNone()); | 42 byte[] byteAttribute = attribute.array(); |
57 | 43 String str = new String(byteAttribute); |
58 TreeMap<String, List< NodePath>> innerIndex = opIndex.some(); | 44 System.out.println("attribute = " + str); |
59 Assert.assertTrue(!innerIndex.get("<-1,0,0>").isNone()); | 45 if (str.equals("<-1,0,1>")) |
46 return true; | |
47 continue; | |
48 } | |
49 } | |
50 return false; | |
51 }, key, "<-1,0,1>"); | |
60 | 52 |
61 JungleTreeEditor editor = tree.getTreeEditor(); | 53 // check index |
62 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(new DefaultNodePath(), 0); | 54 TreeMap<String, TreeMap<String, List<NodePath>>> index = ifTraverser.getIndex(); |
63 editor = either.b(); | 55 Option<TreeMap<String, List<NodePath>>> opIndex = index.get(key); |
64 editor.success(); | |
65 | |
66 ifTraverser.commitIndex(); | |
67 JungleTree newTree = jungle.getTreeByName("tree"); | |
68 InterfaceTraverser newIfTraverser = newTree.getTraverser(); | |
69 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = newIfTraverser.getIndex(); | |
70 Assert.assertTrue(newIndex.isEmpty()); | |
71 | |
72 InterfaceTraverser ifTraverser1= tree.getTraverser(); | |
73 | 56 |
74 ifTraverser1.find((TreeNode node) -> { | 57 Assert.assertTrue(!opIndex.isNone()); |
75 ByteBuffer attribute = node.getAttributes().get(key); | |
76 if (attribute != null) { | |
77 byte[] byteAttribute = attribute.array(); | |
78 String str = new String(byteAttribute); | |
79 System.out.println("attribute = " + str); | |
80 return str.equals("<-1,0,1>"); | |
81 } | |
82 return false; | |
83 }, key, "<-1,0,1>"); | |
84 | |
85 ifTraverser1.commitIndex(); | |
86 JungleTree newTree2 = jungle.getTreeByName("tree"); | |
87 InterfaceTraverser newIfTraverser2 = newTree2.getTraverser(); | |
88 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex1 = newIfTraverser2.getIndex(); | |
89 Assert.assertFalse(newIndex1.isEmpty()); | |
90 | 58 |
91 } | 59 TreeMap<String, List<NodePath>> innerIndex = opIndex.some(); |
60 Assert.assertTrue(!innerIndex.get("<-1,0,0>").isNone()); | |
92 | 61 |
93 public boolean compare(TreeNode compareNode, String compareAttribute) { | 62 JungleTreeEditor editor = tree.getTreeEditor(); |
94 String labName = compareNode.getAttributes().getString(key); | 63 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(new DefaultNodePath(), 0); |
95 if (labName.equals(compareAttribute)) | 64 editor = either.b(); |
96 return true; | 65 editor.success(); |
97 return false; | |
98 } | |
99 | 66 |
100 public static String key = "KEY"; | 67 ifTraverser.commitIndex(); |
101 public static DefaultTreeNode factory = new DefaultTreeNode(); | 68 JungleTree newTree = jungle.getTreeByName("tree"); |
69 InterfaceTraverser newIfTraverser = newTree.getTraverser(); | |
70 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex = newIfTraverser.getIndex(); | |
71 Assert.assertTrue(newIndex.isEmpty()); | |
102 | 72 |
103 public void createTree(JungleTree tree) { | 73 InterfaceTraverser ifTraverser1 = tree.getTraverser(); |
104 NodePath root = new DefaultNodePath(); | |
105 createChildren(tree, root, 0); | |
106 | 74 |
107 for (int x = 0; x < 2; x++) { | 75 ifTraverser1.find((TreeNode node) -> { |
108 createChildren(tree, root.add(0), x); | 76 List<ByteBuffer> attributeList = node.getAttributes().get(key); |
109 for (int y = 0; y < 2; y++) { | 77 if (attributeList.isNotEmpty()) { |
110 createChildren(tree, root.add(0).add(x), y); | 78 for (ByteBuffer attribute : attributeList) { |
111 } | 79 byte[] byteAttribute = attribute.array(); |
112 } | 80 String str = new String(byteAttribute); |
81 System.out.println("attribute = " + str); | |
82 if (str.equals("<-1,0,1>")) | |
83 return true; | |
84 continue; | |
85 } | |
86 } | |
87 return false; | |
88 }, key, "<-1,0,1>"); | |
113 | 89 |
114 } | 90 ifTraverser1.commitIndex(); |
91 JungleTree newTree2 = jungle.getTreeByName("tree"); | |
92 InterfaceTraverser newIfTraverser2 = newTree2.getTraverser(); | |
93 TreeMap<String, TreeMap<String, List<NodePath>>> newIndex1 = newIfTraverser2.getIndex(); | |
94 Assert.assertFalse(newIndex1.isEmpty()); | |
115 | 95 |
116 public void createChildren(JungleTree tree, NodePath root, int num) { | 96 } |
117 JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 | 97 |
118 Either<Error, JungleTreeEditor> either = editor | 98 public boolean compare(TreeNode compareNode, String compareAttribute) { |
119 .addNewChildAt(root, num); // 新しく入れるところへのパス | 99 String labName = compareNode.getAttributes().getString(key).next(); |
120 if (either.isA()) { | 100 if (labName.equals(compareAttribute)) |
121 Assert.fail(); | 101 return true; |
122 } | 102 return false; |
123 editor = either.b(); | 103 } |
124 either = editor.success(); | 104 |
125 if (either.isA()) { | 105 public static String key = "KEY"; |
126 Assert.fail(); | 106 public static DefaultTreeNode factory = new DefaultTreeNode(); |
127 } | 107 |
128 NodePath childPath = root.add(num); | 108 public void createTree(JungleTree tree) { |
129 editor = tree.getTreeEditor(); | 109 NodePath root = new DefaultNodePath(); |
130 NodePath attribute = root.add(num); | 110 createChildren(tree, root, 0); |
131 System.out.println(attribute.toString()); | 111 |
132 either = editor.putAttribute(childPath, key, | 112 for (int x = 0; x < 2; x++) { |
133 ByteBuffer.wrap(attribute.toString().getBytes())); | 113 createChildren(tree, root.add(0), x); |
134 if (either.isA()) { | 114 for (int y = 0; y < 2; y++) { |
135 Assert.fail(); | 115 createChildren(tree, root.add(0).add(x), y); |
136 } | 116 } |
137 editor = either.b(); | 117 } |
138 either = editor.success(); | 118 |
139 } | 119 } |
120 | |
121 public void createChildren(JungleTree tree, NodePath root, int num) { | |
122 JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 | |
123 Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root, num); // 新しく入れるところへのパス | |
124 if (either.isA()) { | |
125 Assert.fail(); | |
126 } | |
127 editor = either.b(); | |
128 either = editor.success(); | |
129 if (either.isA()) { | |
130 Assert.fail(); | |
131 } | |
132 NodePath childPath = root.add(num); | |
133 editor = tree.getTreeEditor(); | |
134 NodePath attribute = root.add(num); | |
135 System.out.println(attribute.toString()); | |
136 either = editor.putAttribute(childPath, key, ByteBuffer.wrap(attribute.toString().getBytes())); | |
137 if (either.isA()) { | |
138 Assert.fail(); | |
139 } | |
140 editor = either.b(); | |
141 either = editor.success(); | |
142 } | |
140 } | 143 } |