github.com/leanovate/gopter@v0.2.9/prop/forall_no_shrink_test.go (about)

     1  package prop_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/leanovate/gopter"
     7  	"github.com/leanovate/gopter/gen"
     8  	"github.com/leanovate/gopter/prop"
     9  )
    10  
    11  func TestForAllNoShrink(t *testing.T) {
    12  	parameters := gopter.DefaultTestParameters()
    13  	simpleForAll := prop.ForAllNoShrink1(
    14  		gen.Const("const value"),
    15  		func(value interface{}) (interface{}, error) {
    16  			return value.(string) == "const value", nil
    17  		},
    18  	)
    19  
    20  	simpleResult := simpleForAll.Check(parameters)
    21  
    22  	if simpleResult.Status != gopter.TestPassed || simpleResult.Succeeded != parameters.MinSuccessfulTests {
    23  		t.Errorf("Invalid simpleResult: %#v", simpleResult)
    24  	}
    25  
    26  	simpleForAllFail := prop.ForAllNoShrink1(
    27  		gen.Const("const value"),
    28  		func(value interface{}) (interface{}, error) {
    29  			return value.(string) != "const value", nil
    30  		},
    31  	)
    32  
    33  	simpleResultFail := simpleForAllFail.Check(parameters)
    34  
    35  	if simpleResultFail.Status != gopter.TestFailed || simpleResultFail.Succeeded != 0 {
    36  		t.Errorf("Invalid simpleResultFail: %#v", simpleResultFail)
    37  	}
    38  
    39  	fail := prop.ForAllNoShrink(0)
    40  	result := fail(gopter.DefaultGenParameters())
    41  	if result.Status != gopter.PropError {
    42  		t.Errorf("Invalid result: %#v", result)
    43  	}
    44  
    45  	undecided := prop.ForAllNoShrink(func(a int) bool {
    46  		return true
    47  	}, gen.Int().SuchThat(func(interface{}) bool {
    48  		return false
    49  	}))
    50  	result = undecided(gopter.DefaultGenParameters())
    51  	if result.Status != gopter.PropUndecided {
    52  		t.Errorf("Invalid result: %#v", result)
    53  	}
    54  }