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
390
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
360
Por que dizemos que Scala é uma linguagem funcional?
pmatiello
0
330
Pistache: A π-Calculus Internal Domain Specific Language for Scala
pmatiello
1
410
Other Decks in Programming
See All in Programming
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
220
すべてのコンテキストを、 ユーザー価値に変える
applism118
3
1.2k
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
120
5つのアンチパターンから学ぶLT設計
narihara
1
160
WebViewの現在地 - SwiftUI時代のWebKit - / The Current State Of WebView
marcy731
0
110
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
160
Is Xcode slowly dying out in 2025?
uetyo
1
250
AI時代のソフトウェア開発を考える(2025/07版) / Agentic Software Engineering Findy 2025-07 Edition
twada
PRO
61
17k
関数型まつりレポート for JuliaTokai #22
antimon2
0
160
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
3
420
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
15
9.8k
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
2.1k
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
730
Done Done
chrislema
184
16k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
60k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
17
950
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.4k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
RailsConf 2023
tenderlove
30
1.1k
KATA
mclloyd
30
14k
Building Adaptive Systems
keathley
43
2.6k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Transcript
SCALACHECK
SCALACHECK Pedro Matiello pedro@pmatiello.me @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 pedro@pmatiello.me @pmatiello