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

Function test

code/data-structures/segment_tree.test.cpp:20–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18};
19
20void test() {
21 /* Field testing: SPOJ HORRIBLE */
22
23 int n = 100000;
24 vector<ll> arr(n);
25 for (int i = 0; i < n; i++) {
26 arr[i] = randint(-1000, 1000);
27 }
28
29 segment_tree x(arr);
30 segment_tree_slow xslow(arr);
31
32 for (int i = 0; i < 100000; i++) {
33 int op = randint(0, 2);
34 if (op == 0) {
35 int a = randint(0, n-1),
36 b = randint(0, n-1);
37 if (a > b) swap(a,b);
38 assert_equal(xslow.query(a, b), x.query(a, b).x);
39 } else if (op == 1) {
40 int idx = randint(0, n-1),
41 val = randint(-1000, 1000);
42 x.update(idx, val);
43 xslow.update(idx, val);
44 } else if (op == 2) {
45 int a = randint(0, n-1),
46 b = randint(0, n-1),
47 v = randint(-1000, 1000);
48
49 if (a > b) swap(a,b);
50
51 x.range_update(a, b, v);
52 xslow.range_update(a, b, v);
53 }
54 }
55}
56// vim: cc=60 ts=2 sts=2 sw=2:

Callers

nothing calls this directly

Calls 5

randintFunction · 0.50
assert_equalFunction · 0.50
queryMethod · 0.45
updateMethod · 0.45
range_updateMethod · 0.45

Tested by

no test coverage detected