(filter): add integer for filter test
This commit is contained in:
parent
93af011977
commit
99026bd939
|
@ -24,6 +24,22 @@ func TestFilter(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIntFilter(t *testing.T) {
|
||||
intMap := gomap.New(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
|
||||
values := []int{2, 4, 6, 8, 10}
|
||||
mappable := intMap.Mappable()
|
||||
filtered := mappable.Filter(func(i interface{}) bool {
|
||||
if value, ok := i.(int); ok {
|
||||
// Filter even numbers.
|
||||
return value%2 == 0
|
||||
}
|
||||
return false
|
||||
})
|
||||
if !reflect.DeepEqual(mapToInt(filtered.Items()), values) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// Benchmark the filtering function.
|
||||
func BenchmarkFilter(b *testing.B) {
|
||||
stringMap := gomap.New("test", "test1", "test2", "not_applicable", "test3")
|
||||
|
@ -47,8 +63,16 @@ func BenchmarkFilter(b *testing.B) {
|
|||
// Map an interface array to a string.
|
||||
func mapToString(i []interface{}) []string {
|
||||
var strArr []string
|
||||
for _, v := range i {
|
||||
for _, v := range i {
|
||||
strArr = append(strArr, v.(string))
|
||||
}
|
||||
return strArr
|
||||
}
|
||||
}
|
||||
|
||||
func mapToInt(i []interface{}) []int {
|
||||
var ia []int
|
||||
for _, v := range i {
|
||||
ia = append(ia, v.(int))
|
||||
}
|
||||
return ia
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue