Property conjunction combines two Prop values into one Prop. The && operator lets independently stated properties participate in a single composable testing expression. section 8.1.2 section 8.1.3
Combining list properties
val intList = Gen.listOf(Gen.choose(0, 100)) val prop = Prop.forAll(intList)(ns => ns.reverse.reverse == ns) && Prop.forAll(intList)(ns => ns.headOption == ns.reverse.lastOption) The expression states that both generated-list properties must hold. section 8.1.2
A naive implementation cannot combine properties if check only prints a report and returns Unit: running both checks produces independent output and discards the information needed for composition. check must return meaningful success or failure data. section 8.1.3
A useful design progression is:
- Represent check results with at least a success/failure distinction so conjunction can decide its result. section 8.1.3
- Consider richer failure information, such as successful-test counts and the arguments that produced failure. section 8.1.3
val intList = Gen.listOf(Gen.choose(0, 100)) val prop = Prop.forAll(intList)(ns => ns.reverse.reverse == ns) && Prop.forAll(intList)(ns => ns.headOption == ns.reverse.lastOption)
Inspect a concrete conjunction of two properties over generated integer lists. section 8.1.2
