-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_product_test.go
More file actions
62 lines (42 loc) · 1.35 KB
/
array_product_test.go
File metadata and controls
62 lines (42 loc) · 1.35 KB
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
package arrayProduct
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestArrayProduct(t *testing.T){
t.Run("it works for empty array", func(t *testing.T) {
var empty []int
result := arrayProduct(empty)
assert.Nil(t, result)
})
t.Run("it works for example array", func(t *testing.T) {
input := []int{2, 3, 4, 5}
result := arrayProduct(input)
assert.NotNil(t, result)
assert.Equal(t, []int{60, 40, 30, 24}, result)
})
t.Run("it works if array has a 0", func(t *testing.T) {
dangerZeros := []int{0, 3, 1}
result := arrayProduct(dangerZeros)
assert.NotNil(t, result)
assert.Equal(t, []int{3, 0, 0}, result)
})
t.Run("it works if array has many 0s", func(t *testing.T) {
dangerZeros := []int{0, 3, 0, 1, 5}
result := arrayProduct(dangerZeros)
assert.NotNil(t, result)
assert.Equal(t, []int{0, 0, 0, 0, 0}, result)
})
t.Run("it works with a single negative number in the array", func(t *testing.T) {
negative := []int{-2, 3, 4, 5}
result := arrayProduct(negative)
assert.NotNil(t, result)
assert.Equal(t, []int{60, -40, -30, -24}, result)
})
t.Run("it works with many negative numbers in the array", func(t *testing.T) {
negatives := []int{-2, 3, -4, -5}
result := arrayProduct(negatives)
assert.NotNil(t, result)
assert.Equal(t, []int{60, -40, 30, 24}, result)
})
}