-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathSegmentTreeTest.java
More file actions
36 lines (28 loc) · 889 Bytes
/
SegmentTreeTest.java
File metadata and controls
36 lines (28 loc) · 889 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
package org.psjava;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class SegmentTreeTest {
// TODO add performance test
@Test
public void testEmpty() {
new SegmentTree<Integer>(Collections.emptyList(), Math::max);
}
@Test
public void testQueryRecursively() {
SegmentTree<Integer> tree = createInitTree();
Assert.assertEquals(10, (int) tree.query(0, 4));
}
@Test
public void testUpdateRecursivelySingle() {
SegmentTree<Integer> tree = createInitTree();
tree.update(0, 2);
Assert.assertEquals(37, (int) tree.query(0, 8));
}
private SegmentTree<Integer> createInitTree() {
List<Integer> init = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
return new SegmentTree<>(init, (a, b) -> a + b);
}
}