github.com/leanovate/gopter@v0.2.9/gen/slice_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 TestSliceShrink(t *testing.T) {
    11  	oneShrink := gen.SliceShrinker(gen.Int64Shrinker)([]int64{0}).All()
    12  	if !reflect.DeepEqual(oneShrink, []interface{}{}) {
    13  		t.Errorf("Invalid oneShrink: %#v", oneShrink)
    14  	}
    15  
    16  	twoShrink := gen.SliceShrinker(gen.Int64Shrinker)([]int64{0, 1}).All()
    17  	if !reflect.DeepEqual(twoShrink, []interface{}{
    18  		[]int64{1},
    19  		[]int64{0},
    20  		[]int64{0, 0},
    21  	}) {
    22  		t.Errorf("Invalid twoShrink: %#v", twoShrink)
    23  	}
    24  
    25  	threeShrink := gen.SliceShrinker(gen.Int64Shrinker)([]int64{0, 1, 2}).All()
    26  	if !reflect.DeepEqual(threeShrink, []interface{}{
    27  		[]int64{1, 2},
    28  		[]int64{0, 2},
    29  		[]int64{0, 1},
    30  		[]int64{0, 0, 2},
    31  		[]int64{0, 1, 0},
    32  		[]int64{0, 1, 1},
    33  		[]int64{0, 1, -1},
    34  	}) {
    35  		t.Errorf("Invalid threeShrink: %#v", threeShrink)
    36  	}
    37  
    38  	fourShrink := gen.SliceShrinker(gen.Int64Shrinker)([]int64{0, 1, 2, 3}).All()
    39  	if !reflect.DeepEqual(fourShrink, []interface{}{
    40  		[]int64{2, 3},
    41  		[]int64{0, 1},
    42  		[]int64{1, 2, 3},
    43  		[]int64{0, 2, 3},
    44  		[]int64{0, 1, 3},
    45  		[]int64{0, 1, 2},
    46  		[]int64{0, 0, 2, 3},
    47  		[]int64{0, 1, 0, 3},
    48  		[]int64{0, 1, 1, 3},
    49  		[]int64{0, 1, -1, 3},
    50  		[]int64{0, 1, 2, 0},
    51  		[]int64{0, 1, 2, 2},
    52  		[]int64{0, 1, 2, -2},
    53  	}) {
    54  		t.Errorf("Invalid fourShrink: %#v", fourShrink)
    55  	}
    56  }
    57  
    58  func TestSliceShrinkOne(t *testing.T) {
    59  	oneShrink := gen.SliceShrinkerOne(gen.Int64Shrinker)([]int64{0}).All()
    60  	if !reflect.DeepEqual(oneShrink, []interface{}{}) {
    61  		t.Errorf("Invalid oneShrink: %#v", oneShrink)
    62  	}
    63  
    64  	threeShrink := gen.SliceShrinkerOne(gen.Int64Shrinker)([]int64{0, 1, 2}).All()
    65  	if !reflect.DeepEqual(threeShrink, []interface{}{
    66  		[]int64{0, 0, 2},
    67  		[]int64{0, 1, 0},
    68  		[]int64{0, 1, 1},
    69  		[]int64{0, 1, -1},
    70  	}) {
    71  		t.Errorf("Invalid threeShrink: %#v", threeShrink)
    72  	}
    73  
    74  	fourShrink := gen.SliceShrinkerOne(gen.Int64Shrinker)([]int64{0, 1, 2, 3}).All()
    75  	if !reflect.DeepEqual(fourShrink, []interface{}{
    76  		[]int64{0, 0, 2, 3},
    77  		[]int64{0, 1, 0, 3},
    78  		[]int64{0, 1, 1, 3},
    79  		[]int64{0, 1, -1, 3},
    80  		[]int64{0, 1, 2, 0},
    81  		[]int64{0, 1, 2, 2},
    82  		[]int64{0, 1, 2, -2},
    83  	}) {
    84  		t.Errorf("Invalid fourShrink: %#v", fourShrink)
    85  	}
    86  }