go-ml.dev/pkg/base@v0.0.0-20200610162856-60c38abac71b/tests/fu_test.go (about) 1 package tests 2 3 import ( 4 "go-ml.dev/pkg/base/fu" 5 "gotest.tools/assert" 6 "gotest.tools/assert/cmp" 7 "reflect" 8 "testing" 9 ) 10 11 func Test_Less1(t *testing.T) { 12 a := map[int]interface{}{0: 0} 13 assert.Assert(t, cmp.Panics(func() { 14 fu.Less(reflect.ValueOf(a), reflect.ValueOf(a)) 15 })) 16 assert.Assert(t, cmp.Panics(func() { 17 fu.Less(reflect.ValueOf(1), reflect.ValueOf("")) 18 })) 19 assert.Assert(t, fu.Less(reflect.ValueOf([2]int{0, 1}), reflect.ValueOf([2]int{0, 2}))) 20 assert.Assert(t, cmp.Panics(func() { 21 fu.Less(reflect.ValueOf([2]int{0, 1}), reflect.ValueOf([1]int{0})) 22 })) 23 } 24 25 func Test_MinMax(t *testing.T) { 26 assert.Assert(t, fu.MinIndex(reflect.ValueOf([]int{1, 2, 3, 4, 5})) == 0) 27 assert.Assert(t, fu.MaxIndex(reflect.ValueOf([]int{1, 2, 3, 4, 5})) == 4) 28 assert.Assert(t, fu.Min(1, 2, 3, 4, 5).(int) == 1) 29 assert.Assert(t, fu.Max(1, 2, 3, 4, 5).(int) == 5) 30 assert.Assert(t, fu.MinValue(reflect.ValueOf([]int{1, 2, 3, 4, 5})).Int() == 1) 31 assert.Assert(t, fu.MaxValue(reflect.ValueOf([]int{1, 2, 3, 4, 5})).Int() == 5) 32 }