1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.utgb;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
30
31 import java.util.HashSet;
32 import java.util.List;
33
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.utgenome.gwt.utgb.client.canvas.PrioritySearchTree;
38
39 public class PrioritySearchTreeTest {
40
41 PrioritySearchTree<String> p;
42
43 @Before
44 public void setUp() throws Exception {
45 p = new PrioritySearchTree<String>();
46 p.insert("A", 1, 2);
47 p.insert("B", 2, 4);
48 p.insert("C", 1, 8);
49 p.insert("D", 3, 3);
50 p.insert("E", 5, 6);
51 }
52
53 @After
54 public void tearDown() throws Exception {
55 }
56
57 @Test
58 public void testRangeQuery() {
59
60 List<String> result = p.rangeQuery(1, 2, 6);
61 assertEquals(2, result.size());
62 assertTrue(result.contains("A"));
63 assertTrue(result.contains("B"));
64
65 result = p.rangeQuery(2, 5, 4);
66 assertEquals(2, result.size());
67 assertTrue(result.contains("B"));
68 assertTrue(result.contains("D"));
69
70 result = p.rangeQuery(2, 5, 10);
71 assertEquals(3, result.size());
72 assertTrue(result.contains("B"));
73 assertTrue(result.contains("E"));
74 assertTrue(result.contains("D"));
75
76 }
77
78 @Test
79 public void testRemove() {
80 p.remove("B", 2, 4);
81
82 List<String> result = p.rangeQuery(1, 2, 6);
83 assertEquals(1, result.size());
84 assertTrue(result.contains("A"));
85 assertFalse(result.contains("B"));
86
87 result = p.rangeQuery(2, 5, 4);
88 assertEquals(1, result.size());
89 assertTrue(result.contains("D"));
90
91 }
92
93 @Test
94 public void iterator() throws Exception {
95
96 HashSet<String> nodeSet = new HashSet<String>();
97
98 int nodeCount = 0;
99 for (String each : p) {
100 nodeCount++;
101 nodeSet.add(each);
102 }
103
104 assertEquals(5, nodeCount);
105 assertTrue(nodeSet.contains("A"));
106 assertTrue(nodeSet.contains("B"));
107 assertTrue(nodeSet.contains("C"));
108 assertTrue(nodeSet.contains("D"));
109 assertTrue(nodeSet.contains("E"));
110 }
111
112 }