MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / test1

Function test1

code/data-structures/fenwick_tree.test.cpp:3–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1/* Field testing: POJ 3468 */
2
3void test1() {
4 fenwick_tree ft(20);
5
6 for (int i = 0; i < 20; i++) {
7 assert_equal(0, ft.rsq(i, i));
8 ft.update(i, i);
9 assert_equal(i, ft.rsq(i, i));
10 ft.update(i, -i);
11 assert_equal(0, ft.rsq(i, i));
12 }
13
14 ft.update(3, 1);
15 for (int i = 0; i < 20; i++)
16 {
17 for (int j = i; j < 20; j++)
18 {
19 if (i <= 3 && 3 <= j)
20 {
21 assert_equal(1, ft.rsq(i, j));
22 }
23 else
24 {
25 assert_equal(0, ft.rsq(i, j));
26 }
27 }
28 }
29
30 ft.update(5, -2);
31 assert_equal(-1, ft.rsq(1, 8));
32 ft.update(4, 5);
33 assert_equal(4, ft.rsq(1, 8));
34 ft.update(0, 100);
35 assert_equal(4, ft.rsq(1, 8));
36 assert_equal(104, ft.rsq(0, 19));
37 ft.update(19, -200);
38 assert_equal(-96, ft.rsq(0, 19));
39}
40
41struct fake_fenwick_tree {
42 vi arr;

Callers 1

testFunction · 0.70

Calls 3

assert_equalFunction · 0.50
rsqMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected