-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcount_occurrences_test.go
47 lines (43 loc) · 1.27 KB
/
count_occurrences_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
package countoccurrences
import "testing"
func TestCountOccurrences(t *testing.T) {
tests := []struct {
name string
intArray []int
valueToFind int
expectedOccurrences int
}{
{
name: "Expect 4 occurrences of the number 3",
intArray: []int{0, 1, 1, 3, 3, 3, 3, 6, 8, 10, 11, 11},
valueToFind: 3,
expectedOccurrences: 4,
},
{
name: "Expect 0 occurrences of the number 2",
intArray: []int{0, 1, 1, 3, 3, 3, 3, 6, 8, 10, 11, 11},
valueToFind: 2,
expectedOccurrences: 0,
},
{
name: "Expect 1 occurrence of the number 8",
intArray: []int{0, 1, 1, 3, 3, 3, 3, 6, 8, 10, 11, 11},
valueToFind: 8,
expectedOccurrences: 1,
},
{
name: "Expect 2 occurrence of the number 11",
intArray: []int{0, 1, 1, 3, 3, 3, 3, 6, 8, 10, 11, 11},
valueToFind: 11,
expectedOccurrences: 2,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
received := countOccurrences(test.valueToFind, test.intArray)
if received != test.expectedOccurrences {
t.Errorf("Expected index %d, received %d instead.", test.expectedOccurrences, received)
}
})
}
}