github.com/leanovate/gopter@v0.2.9/gen/floats_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 TestFloat64Shrinker(t *testing.T) {
    11  	zeroShrinks := gen.Float64Shrinker(float64(0)).All()
    12  	if !reflect.DeepEqual(zeroShrinks, []interface{}{}) {
    13  		t.Errorf("Invalid zeroShrinks: %#v", zeroShrinks)
    14  	}
    15  
    16  	oneShrinks := gen.Float64Shrinker(float64(1)).All()
    17  	if !reflect.DeepEqual(oneShrinks, []interface{}{
    18  		0.0,
    19  		0.5,
    20  		-0.5,
    21  		0.75,
    22  		-0.75,
    23  		0.875,
    24  		-0.875,
    25  		0.9375,
    26  		-0.9375,
    27  		0.96875,
    28  		-0.96875,
    29  		0.984375,
    30  		-0.984375,
    31  		0.9921875,
    32  		-0.9921875,
    33  		0.99609375,
    34  		-0.99609375,
    35  		0.998046875,
    36  		-0.998046875,
    37  		0.9990234375,
    38  		-0.9990234375,
    39  		0.99951171875,
    40  		-0.99951171875,
    41  		0.999755859375,
    42  		-0.999755859375,
    43  		0.9998779296875,
    44  		-0.9998779296875,
    45  		0.99993896484375,
    46  		-0.99993896484375,
    47  		0.999969482421875,
    48  		-0.999969482421875,
    49  		0.9999847412109375,
    50  		-0.9999847412109375,
    51  	}) {
    52  		t.Errorf("Invalid tenShrinks: %#v", oneShrinks)
    53  	}
    54  
    55  	hundretShrinks := gen.Float64Shrinker(float64(100)).All()
    56  	if !reflect.DeepEqual(hundretShrinks, []interface{}{
    57  		0.0,
    58  		50.0,
    59  		-50.0,
    60  		75.0,
    61  		-75.0,
    62  		87.5,
    63  		-87.5,
    64  		93.75,
    65  		-93.75,
    66  		96.875,
    67  		-96.875,
    68  		98.4375,
    69  		-98.4375,
    70  		99.21875,
    71  		-99.21875,
    72  		99.609375,
    73  		-99.609375,
    74  		99.8046875,
    75  		-99.8046875,
    76  		99.90234375,
    77  		-99.90234375,
    78  		99.951171875,
    79  		-99.951171875,
    80  		99.9755859375,
    81  		-99.9755859375,
    82  		99.98779296875,
    83  		-99.98779296875,
    84  		99.993896484375,
    85  		-99.993896484375,
    86  		99.9969482421875,
    87  		-99.9969482421875,
    88  		99.99847412109375,
    89  		-99.99847412109375,
    90  		99.99923706054688,
    91  		-99.99923706054688,
    92  		99.99961853027344,
    93  		-99.99961853027344,
    94  		99.99980926513672,
    95  		-99.99980926513672,
    96  		99.99990463256836,
    97  		-99.99990463256836,
    98  		99.99995231628418,
    99  		-99.99995231628418,
   100  		99.99997615814209,
   101  		-99.99997615814209,
   102  		99.99998807907104,
   103  		-99.99998807907104,
   104  	}) {
   105  		t.Errorf("Invalid hundretShrinks: %#v", hundretShrinks)
   106  	}
   107  }
   108  
   109  func TestFloat32Shrinker(t *testing.T) {
   110  	zeroShrinks := gen.Float32Shrinker(float32(0)).All()
   111  	if !reflect.DeepEqual(zeroShrinks, []interface{}{}) {
   112  		t.Errorf("Invalid zeroShrinks: %#v", zeroShrinks)
   113  	}
   114  
   115  	oneShrinks := gen.Float32Shrinker(float32(1)).All()
   116  	if !reflect.DeepEqual(oneShrinks, []interface{}{
   117  		float32(0),
   118  		float32(0.5),
   119  		float32(-0.5),
   120  		float32(0.75),
   121  		float32(-0.75),
   122  		float32(0.875),
   123  		float32(-0.875),
   124  		float32(0.9375),
   125  		float32(-0.9375),
   126  		float32(0.96875),
   127  		float32(-0.96875),
   128  		float32(0.984375),
   129  		float32(-0.984375),
   130  		float32(0.9921875),
   131  		float32(-0.9921875),
   132  		float32(0.99609375),
   133  		float32(-0.99609375),
   134  		float32(0.9980469),
   135  		float32(-0.9980469),
   136  		float32(0.99902344),
   137  		float32(-0.99902344),
   138  		float32(0.9995117),
   139  		float32(-0.9995117),
   140  		float32(0.99975586),
   141  		float32(-0.99975586),
   142  		float32(0.9998779),
   143  		float32(-0.9998779),
   144  		float32(0.99993896),
   145  		float32(-0.99993896),
   146  		float32(0.9999695),
   147  		float32(-0.9999695),
   148  		float32(0.99998474),
   149  		float32(-0.99998474),
   150  	}) {
   151  		t.Errorf("Invalid tenShrinks: %#v", oneShrinks)
   152  	}
   153  
   154  }