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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Pedro Matiello
August 28, 2013
Programming
420
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ScalaCheck
Presented at Scaladores, August/2013
Pedro Matiello
August 28, 2013
More Decks by Pedro Matiello
See All by Pedro Matiello
Lazy Evaluation em Scala
pmatiello
0
410
Por que dizemos que Scala é uma linguagem funcional?
pmatiello
0
390
Pistache: A π-Calculus Internal Domain Specific Language for Scala
pmatiello
1
470
Other Decks in Programming
See All in Programming
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
110
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
210
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
200
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
200
さぁV100、メモリをお食べ・・・
nilpe
0
150
Creating Composable Callables in Contemporary C++
rollbear
0
150
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
550
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
290
Oxlintのカスタムルールの現況
syumai
6
1.1k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
720
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.3k
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Pragmatic Product Professional
lauravandoore
37
7.3k
GraphQLとの向き合い方2022年版
quramy
50
15k
Music & Morning Musume
bryan
47
7.2k
Embracing the Ebb and Flow
colly
88
5.1k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
200
Optimizing for Happiness
mojombo
378
71k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Chasing Engaging Ingredients in Design
codingconduct
0
220
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
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