github.com/leanovate/gopter@v0.2.9/gen/map_shrink_test.go (about) 1 package gen_test 2 3 import ( 4 "reflect" 5 "testing" 6 7 "github.com/leanovate/gopter/gen" 8 ) 9 10 func TestMapShrinkerOne(t *testing.T) { 11 mapShrink := gen.MapShrinkerOne(gen.StringShrinker, gen.Int64Shrinker)(map[string]int64{ 12 "two": 2, 13 }).All() 14 if !reflect.DeepEqual(mapShrink, []interface{}{ 15 map[string]int64{"wo": 2}, 16 map[string]int64{"wo": 0}, 17 map[string]int64{"to": 0}, 18 map[string]int64{"to": 1}, 19 map[string]int64{"tw": 1}, 20 map[string]int64{"tw": -1}, 21 }) { 22 t.Errorf("Invalid mapShrink: %#v", mapShrink) 23 } 24 } 25 26 func TestMapShrinker(t *testing.T) { 27 mapShrink := gen.MapShrinker(gen.StringShrinker, gen.Int64Shrinker)(map[string]int64{ 28 "two": 2, 29 }).All() 30 if !reflect.DeepEqual(mapShrink, []interface{}{ 31 map[string]int64{"wo": 2}, 32 map[string]int64{"wo": 0}, 33 map[string]int64{"to": 0}, 34 map[string]int64{"to": 1}, 35 map[string]int64{"tw": 1}, 36 map[string]int64{"tw": -1}, 37 }) { 38 t.Errorf("Invalid mapShrink: %#v", mapShrink) 39 } 40 41 mapShrink2 := gen.MapShrinker(gen.StringShrinker, gen.Int64Shrinker)(map[string]int64{ 42 "one": 1, 43 "two": 2, 44 "three": 3, 45 "four": 3, 46 }).All() 47 48 if len(mapShrink2) < 10 { 49 t.Errorf("mapShrink2 too short: %#v", mapShrink2) 50 } 51 for _, shrink := range mapShrink2 { 52 _, ok := shrink.(map[string]int64) 53 if !ok { 54 t.Errorf("mapShrink2 invalid type: %#v", mapShrink2) 55 } 56 } 57 }