Pedro Matiello
August 28, 2013
340

# ScalaCheck

August 28, 2013

## Transcript

6. ### PROPERTIES def sum(x:Int, y:Int) = x + y # Property:

∀x,y : sum(x,y) = sum(y,x)
7. ### PROPERTIES def sum(x:Int, y:Int) = x + y # Property:

∀x,y : sum(x,y) = sum(y,x) val commutativity = forAll { (x:Int, y:Int) => sum(x,y) == sum(y,x) }
8. ### PROPERTIES def sum(x:Int, y:Int) = x + y # Property:

∀x,y : sum(x,y) = sum(y,x) val commutativity = forAll { (x:Int, y:Int) => sum(x,y) == sum(y,x) }
9. ### PROPERTIES def sum(x:Int, y:Int) = x + y # Property:

∀x,y : sum(x,y) = sum(y,x) val commutativity = forAll { (x:Int, y:Int) => sum(x,y) == sum(y,x) } org.scalacheck.Prop.forAll
10. ### PROPERTIES def sum(x:Int, y:Int) = x + y # Property:

∀x,y : sum(x,y) = sum(y,x) val commutativity = forAll { (x:Int, y:Int) => sum(x,y) == sum(y,x) } commutativity.check
11. ### PROPERTIES def sum(x:Int, y:Int) = x + y # Property:

∀x,y : sum(x,y) = sum(y,x) val commutativity = forAll { (x:Int, y:Int) => sum(x,y) == sum(y,x) } commutativity.check + OK, passed 100 tests

13. ### CONDITIONAL PROPERTIES def sum(x:Int, y:Int) = x + y #

Property: ∀x,y>0 : sum(x,y) > x
14. ### CONDITIONAL PROPERTIES def sum(x:Int, y:Int) = x + y #

Property: ∀x,y>0 : sum(x,y) > x val greater = forAll { (x:Int, y:Int) => y > 0 ==> sum(x,y) > x }
15. ### CONDITIONAL PROPERTIES def sum(x:Int, y:Int) = x + y #

Property: ∀x,y>0 : sum(x,y) > x val greater = forAll { (x:Int, y:Int) => y > 0 ==> sum(x,y) > x }
16. ### CONDITIONAL PROPERTIES def sum(x:Int, y:Int) = x + y #

Property: ∀x,y>0 : sum(x,y) > x val greater = forAll { (x:Int, y:Int) => y > 0 ==> sum(x,y) > x } greater.check
17. ### CONDITIONAL PROPERTIES def sum(x:Int, y:Int) = x + y #

Property: ∀x,y>0 : sum(x,y) > x val greater = forAll { (x:Int, y:Int) => y > 0 ==> sum(x,y) > x } greater.check ! Falsified after 2 passed tests. > ARG_0: 51047075 > ARG_1: 2096436573

19. ### CONDITIONAL PROPERTIES scala> 51047075 + 2096436573 res0: Int = -2147483648

scala> 51047075l + 2096436573l res1: Long = 2147483648

21. ### GENERATORS def sum(x:Int, y:Int) = x + y # ∀x,y,

x%2=0,y%2=0 : sum(x,y)%2 = 0
22. ### GENERATORS def sum(x:Int, y:Int) = x + y # ∀x,y,

x%2=0,y%2=0 : sum(x,y)%2 = 0 val evenInt = arbitrary[Int] suchThat (_ % 2 == 0)
23. ### GENERATORS def sum(x:Int, y:Int) = x + y # ∀x,y,

x%2=0,y%2=0 : sum(x,y)%2 = 0 val evenInt = arbitrary[Int] suchThat (_ % 2 == 0) org.scalacheck.Arbitrary.arbitrary
24. ### GENERATORS def sum(x:Int, y:Int) = x + y # ∀x,y,

x%2=0,y%2=0 : sum(x,y)%2 = 0 val evenInt = arbitrary[Int] suchThat (_ % 2 == 0) forAll(evenInt, evenInt) { (x:Int, y:Int) => sum(x,y) % 2 == 0 }.check
25. ### GENERATORS def sum(x:Int, y:Int) = x + y # ∀x,y,

x%2=0,y%2=0 : sum(x,y)%2 = 0 val evenInt = arbitrary[Int] suchThat (_ % 2 == 0) forAll(evenInt, evenInt) { (x:Int, y:Int) => sum(x,y) % 2 == 0 }.check
26. ### GENERATORS def sum(x:Int, y:Int) = x + y # ∀x,y,

x%2=0,y%2=0 : sum(x,y)%2 = 0 val evenInt = arbitrary[Int] suchThat (_ % 2 == 0) forAll(evenInt, evenInt) { (x:Int, y:Int) => sum(x,y) % 2 == 0 }.check + OK, passed 100 tests