-
Notifications
You must be signed in to change notification settings - Fork 0
/
num_test.go
68 lines (48 loc) · 1.05 KB
/
num_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package giter
import (
"reflect"
"testing"
)
func TestSum(t *testing.T) {
xs := []int{1, 2, 3, 4, 5}
want := 0
for _, x := range xs {
want += x
}
out := Sum(Slice(xs))
if want != out {
t.Errorf("TestSum: out = %v, want %v", out, want)
}
}
func TestProd(t *testing.T) {
xs := []int{1, 2, 3, 4, 5}
want := 1
for _, x := range xs {
want *= x
}
out := Prod(Slice(xs))
if want != out {
t.Errorf("TestProd: out = %v, want %v", out, want)
}
}
func TestRange(t *testing.T) {
want := []int{1, 2, 3, 4, 5}
out := ToSlice(Range(1, 6))
if !reflect.DeepEqual(want, out) {
t.Errorf("TestRange: out = %v, want %v", out, want)
}
}
func TestFpRange(t *testing.T) {
want := []float64{1.0, 2.0, 3.0, 4.0, 5.0}
out := ToSlice(Range[float64](1, 6))
if !reflect.DeepEqual(want, out) {
t.Errorf("TestFpRange: out = %v, want %v", out, want)
}
}
func TestRangeBy(t *testing.T) {
want := []int{10, 20, 30, 40, 50}
out := ToSlice(RangeBy(10, 55, 10))
if !reflect.DeepEqual(want, out) {
t.Errorf("TestRangeBy: out = %v, want %v", out, want)
}
}