-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber_filtering_test.go
91 lines (75 loc) · 2.4 KB
/
number_filtering_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package exercises
import (
"reflect"
"testing"
)
func TestFilter_1(t *testing.T) {
input := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
output := []int{2, 4, 6, 8, 10}
got := Filter_nums(input, IsEven)
if reflect.DeepEqual(got, output) {
t.Errorf("got %v wanted %v ", got, output)
}
}
func TestFilter_2(t *testing.T) {
input := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
output := []int{1, 3, 5, 7, 9}
got := Filter_nums(input, IsOdd)
if reflect.DeepEqual(got, output) {
t.Errorf("got %v wanted %v ", got, output)
}
}
func TestFilter_3(t *testing.T) {
input := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
output := []int{2, 3, 5, 7}
got := Filter_nums(input, IsPrime)
if reflect.DeepEqual(got, output) {
t.Errorf("got %v wanted %v ", got, output)
}
}
func TestFilter_4(t *testing.T) {
input := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
output := []int{3, 5, 7}
got := Filter_nums(input, IsOddPrime)
if reflect.DeepEqual(got, output) {
t.Errorf("got %v wanted %v ", got, output)
}
}
func TestFilter_5(t *testing.T) {
input := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
output := []int{10, 20}
got := Filter_nums(input, IsEvenMultipleOf(5))
if reflect.DeepEqual(got, output) {
t.Errorf("got %v wanted %v ", got, output)
}
}
func TestFilter_6(t *testing.T) {
input := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
output := []int{15}
got := Filter_nums(input, IsOddGreaterAndMultipleOf(10, 3))
if reflect.DeepEqual(got, output) {
t.Errorf("got %v wanted %v ", got, output)
}
}
func TestFilter_7(t *testing.T) {
input1 := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
output1 := []int{9, 15}
//output2 := []int{6,12}
greater_than_five := IsGreater(5)
multiple_of_three := IsMultipleOf(3)
got1 := FilterByConds(input1, All, IsOdd, greater_than_five, multiple_of_three)
if reflect.DeepEqual(got1, output1) {
t.Errorf("got %v wanted %v ", got1, output1)
}
}
func TestFilter_8(t *testing.T) {
input1 := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
output1 := []int{2, 3, 5, 7, 10, 11, 13, 15, 16, 17, 18, 19, 20}
//output2 := []int{6,12}
greater_than_fifteen := IsGreater(15)
multiple_of_five := IsMultipleOf(5)
got1 := FilterByConds(input1, Any, IsPrime, greater_than_fifteen, multiple_of_five)
if reflect.DeepEqual(got1, output1) {
t.Errorf("got %v wanted %v ", got1, output1)
}
}