Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ScalaCheck
Search
Pedro Matiello
August 28, 2013
Programming
1
350
ScalaCheck
Presented at Scaladores, August/2013
Pedro Matiello
August 28, 2013
Tweet
Share
More Decks by Pedro Matiello
See All by Pedro Matiello
Lazy Evaluation em Scala
pmatiello
0
310
Por que dizemos que Scala é uma linguagem funcional?
pmatiello
0
250
Pistache: A π-Calculus Internal Domain Specific Language for Scala
pmatiello
1
370
Other Decks in Programming
See All in Programming
入社1ヶ月でここまでやった!Findy Toolsインフラ支援の最適化
rvirus0817
6
1.4k
CSC307 Lecture 10
javiergs
PRO
0
310
【Go言語】ジェネリクス
tomo1227
0
170
OpenAI/Gemini APIを使って EPUBを翻訳するCLIツールをつくってみた
tomiyan
0
790
Folding Cheat Sheet #7
philipschwarz
PRO
0
150
Webエディタライブラリ 「CodeMirror」から学ぶ Webアプリ開発のテクニック
ryosukeigarashi
0
250
Exploring the Gradually Lost Technical Skills in the Cloud Native Era
hwchiu
2
3.9k
Advanced App Shrinking Techniques
cbeyls
2
150
유연한 Composable 설계
l2hyunwoo
0
380
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
2
81k
AWSでゲームサーバーを運用! Amazon GameLiftのお話
iriikeita
0
200
CSC307 Lecture 06
javiergs
PRO
0
360
Featured
See All Featured
What the flash - Photography Introduction
edds
65
11k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
78
15k
Become a Pro
speakerdeck
PRO
15
4.8k
A Modern Web Designer's Workflow
chriscoyier
689
190k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
13
430
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Navigating Team Friction
lara
181
13k
WebSockets: Embracing the real-time Web
robhawkes
59
7.2k
Git: the NoSQL Database
bkeepers
PRO
423
64k
Fireside Chat
paigeccino
25
2.8k
Mobile First: as difficult as doing things right
swwweet
219
8.8k
Transcript
SCALACHECK
SCALACHECK Pedro Matiello
[email protected]
@pmatiello
SCALACHECK • Property-based testing • Scala
PROPERTIES
PROPERTIES def sum(x:Int, y:Int) = x + y
PROPERTIES def sum(x:Int, y:Int) = x + y # Property:
∀x,y : sum(x,y) = sum(y,x)
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) }
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) }
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
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
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
CONDITIONAL PROPERTIES
CONDITIONAL PROPERTIES def sum(x:Int, y:Int) = x + y #
Property: ∀x,y>0 : sum(x,y) > x
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 }
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 }
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
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
CONDITIONAL PROPERTIES scala> 51047075 + 2096436573 res0: Int = -2147483648
CONDITIONAL PROPERTIES scala> 51047075 + 2096436573 res0: Int = -2147483648
scala> 51047075l + 2096436573l res1: Long = 2147483648
GENERATORS
GENERATORS def sum(x:Int, y:Int) = x + y # ∀x,y,
x%2=0,y%2=0 : sum(x,y)%2 = 0
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)
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
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
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
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
SCALACHECK Pedro Matiello
[email protected]
@pmatiello