This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils_test.go
44 lines (37 loc) · 1.49 KB
/
utils_test.go
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
package speedtest
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func Test_MaximalSumWindow(t *testing.T) {
Convey("Calculate window sum, size 1", t, func() {
So(MaximalSumWindow([]int{1, 2, 3, 4, 5}, 1), ShouldEqual, 5)
So(MaximalSumWindow([]int{3, 4, 5, 1, 2}, 1), ShouldEqual, 5)
So(MaximalSumWindow([]int{5, 1, 2, 3, 4}, 1), ShouldEqual, 5)
})
Convey("Calculate window sum, size 2", t, func() {
So(MaximalSumWindow([]int{1, 2, 3, 4, 5}, 2), ShouldEqual, 9)
So(MaximalSumWindow([]int{3, 4, 5, 1, 2}, 2), ShouldEqual, 9)
So(MaximalSumWindow([]int{5, 1, 2, 3, 4}, 2), ShouldEqual, 7)
})
Convey("Calculate window sum, size 5", t, func() {
So(MaximalSumWindow([]int{1, 2, 3, 4, 5}, 5), ShouldEqual, 15)
So(MaximalSumWindow([]int{3, 4, 5, 1, 2}, 5), ShouldEqual, 15)
So(MaximalSumWindow([]int{5, 1, 2, 3, 4}, 5), ShouldEqual, 15)
})
Convey("Should restrict window", t, func() {
So(MaximalSumWindow([]int{1, 2, 3}, 5), ShouldEqual, 6)
})
}
func Test_MedianSumWindow(t *testing.T) {
Convey("Calculate window sum, size 1", t, func() {
So(MedianSumWindow([]int{1, 2, 3, 4, 5}, 1), ShouldEqual, 3)
So(MedianSumWindow([]int{3, 4, 5, 1, 2}, 1), ShouldEqual, 3)
So(MedianSumWindow([]int{5, 1, 2, 3, 4}, 1), ShouldEqual, 3)
})
Convey("Calculate window sum, size 3", t, func() {
So(MedianSumWindow([]int{1, 2, 3, 4, 5}, 3), ShouldEqual, 9)
So(MedianSumWindow([]int{3, 4, 5, 1, 2}, 3), ShouldEqual, 9)
So(MedianSumWindow([]int{5, 1, 2, 3, 4}, 3), ShouldEqual, 9)
})
}