-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathac_fenwicktree_test.go2
69 lines (64 loc) · 1.29 KB
/
ac_fenwicktree_test.go2
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
// vim:set ft=go:
import (
"testing"
)
// vim:set ft=go:
func TestFenwickTree(t *testing.T) {
N := 5
ft := NewFenwickTree[int](N)
tests := []struct {
title string
input []int
want [][]int
wantsize []int
}{
{
title: "0 2",
input: []int{0, 2},
want: [][]int{
[]int{0, 2, 2, 2, 2, 2},
[]int{0, 0, 0, 0, 0, 0},
[]int{0, 0, 0, 0, 0, 0},
[]int{0, 0, 0, 0, 0, 0},
[]int{0, 0, 0, 0, 0, 0},
},
},
{
title: "1 3",
input: []int{1, 3},
want: [][]int{
[]int{0, 2, 5, 5, 5, 5},
[]int{0, 0, 3, 3, 3, 3},
[]int{0, 0, 0, 0, 0, 0},
[]int{0, 0, 0, 0, 0, 0},
[]int{0, 0, 0, 0, 0, 0},
},
},
{
title: "2 3",
input: []int{2, 3},
want: [][]int{
[]int{0, 2, 5, 8, 8, 8},
[]int{0, 0, 3, 6, 6, 6},
[]int{0, 0, 0, 3, 3, 3},
[]int{0, 0, 0, 0, 0, 0},
[]int{0, 0, 0, 0, 0, 0},
},
},
}
for _, ts := range tests {
t.Run("FenwickTree.Add:"+ts.title, func(t *testing.T) {
ft.Add(ts.input[0], ts.input[1])
for i := 0; i < N; i++ {
for j := i; j <= N; j++ {
want := ts.want[i][j]
got := ft.Sum(i, j)
if want != got {
t.Errorf("ft.Sum(%d, %d) after ft.Add(%d, %d) returns wrong value: want=%v got=%v\n", i, j, ts.input[0], ts.input[1], want, got)
}
}
}
})
}
}