1 package funk
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestMinWithArrayNumericInput(t *testing.T) {
10
11 d1 := []int{8, 3, 4, 44, 0}
12 n1 := []int{}
13 d2 := []int8{3, 3, 5, 9, 1}
14 n2 := []int8{}
15 d3 := []int16{4, 5, 4, 33, 2}
16 n3 := []int16{}
17 d4 := []int32{5, 3, 21, 15, 3}
18 n4 := []int32{}
19 d5 := []int64{9, 3, 9, 1, 2}
20 n5 := []int64{}
21
22 r1 := MinInt(d1)
23 r2 := MinInt8(d2)
24 r3 := MinInt16(d3)
25 r4 := MinInt32(d4)
26 r5 := MinInt64(d5)
27
28 assert.Equal(t, int(0), r1, "It should return the min value in array")
29 assert.Panics(t, func() { MinInt(n1) }, "It should panic")
30 assert.Equal(t, int8(1), r2, "It should return the min value in array")
31 assert.Panics(t, func() { MinInt8(n2) }, "It should panic")
32 assert.Equal(t, int16(2), r3, "It should return the min value in array")
33 assert.Panics(t, func() { MinInt16(n3) }, "It should panic")
34 assert.Equal(t, int32(3), r4, "It should return the min value in array")
35 assert.Panics(t, func() { MinInt32(n4) }, "It should panic")
36 assert.Equal(t, int64(1), r5, "It should return the min value in array")
37 assert.Panics(t, func() { MinInt64(n5) }, "It should panic")
38
39 }
40
41 func TestMinWithArrayFloatInput(t *testing.T) {
42
43 d1 := []float64{2, 38.3, 4, 4.4, 4}
44 n1 := []float64{}
45 d2 := []float32{2.9, 1.3, 4.23, 4.4, 7.7}
46 n2 := []float32{}
47
48 r1 := MinFloat64(d1)
49 r2 := MinFloat32(d2)
50
51 assert.Equal(t, float64(2), r1, "It should return the min value in array")
52 assert.Panics(t, func() { MinFloat64(n1) }, "It should panic")
53 assert.Equal(t, float32(1.3), r2, "It should return the min value in array")
54 assert.Panics(t, func() { MinFloat32(n2) }, "It should panic")
55 }
56
57 func TestMinWithArrayInputWithStrings(t *testing.T) {
58
59 d1 := []string{"abc", "abd", "cbd"}
60 d2 := []string{"abc", "abd", "abe"}
61 d3 := []string{"abc", "foo", " "}
62 d4 := []string{"abc", "abc", "aaa"}
63 n1 := []string{}
64
65 r1 := MinString(d1)
66 r2 := MinString(d2)
67 r3 := MinString(d3)
68 r4 := MinString(d4)
69
70 assert.Equal(t, "abc", r1, "It should print cbd because its first char is min in the list")
71 assert.Equal(t, "abc", r2, "It should print abe because its first different char is min in the list")
72 assert.Equal(t, " ", r3, "It should print foo because its first different char is min in the list")
73 assert.Equal(t, "aaa", r4, "It should print abc because its first different char is min in the list")
74 assert.Panics(t, func() { MinString(n1) }, "It should panic")
75 }
76
View as plain text