1package funk 2 3import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7) 8 9func TestMaxWithArrayNumericInput(t *testing.T) { 10 //Test Data 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 //Calls 22 r1 := MaxInt(d1) 23 r2 := MaxInt8(d2) 24 r3 := MaxInt16(d3) 25 r4 := MaxInt32(d4) 26 r5 := MaxInt64(d5) 27 // Assertions 28 assert.Equal(t, int(44), r1, "It should return the max value in array") 29 assert.Panics(t, func() { MaxInt(n1) }, "It should panic") 30 assert.Equal(t, int8(9), r2, "It should return the max value in array") 31 assert.Panics(t, func() { MaxInt8(n2) }, "It should panic") 32 assert.Equal(t, int16(33), r3, "It should return the max value in array") 33 assert.Panics(t, func() { MaxInt16(n3) }, "It should panic") 34 assert.Equal(t, int32(21), r4, "It should return the max value in array") 35 assert.Panics(t, func() { MaxInt32(n4) }, "It should panic") 36 assert.Equal(t, int64(9), r5, "It should return the max value in array") 37 assert.Panics(t, func() { MaxInt64(n5) }, "It should panic") 38 39} 40 41func TestMaxWithArrayFloatInput(t *testing.T) { 42 //Test Data 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 //Calls 48 r1 := MaxFloat64(d1) 49 r2 := MaxFloat32(d2) 50 // Assertions 51 assert.Equal(t, float64(38.3), r1, "It should return the max value in array") 52 assert.Panics(t, func() { MaxFloat64(n1) }, "It should panic") 53 assert.Equal(t, float32(7.7), r2, "It should return the max value in array") 54 assert.Panics(t, func() { MaxFloat32(n2) }, "It should panic") 55} 56 57func TestMaxWithArrayInputWithStrings(t *testing.T) { 58 //Test Data 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 //Calls 65 r1 := MaxString(d1) 66 r2 := MaxString(d2) 67 r3 := MaxString(d3) 68 r4 := MaxString(d4) 69 // Assertions 70 assert.Equal(t, "cbd", r1, "It should print cbd because its first char is max in the list") 71 assert.Equal(t, "abe", r2, "It should print abe because its first different char is max in the list") 72 assert.Equal(t, "foo", r3, "It should print foo because its first different char is max in the list") 73 assert.Equal(t, "abc", r4, "It should print abc because its first different char is max in the list") 74 assert.Panics(t, func() { MaxString(n1) }, "It should panic") 75} 76