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
340
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
290
Por que dizemos que Scala é uma linguagem funcional?
pmatiello
0
230
Pistache: A π-Calculus Internal Domain Specific Language for Scala
pmatiello
1
360
Other Decks in Programming
See All in Programming
自動テスト実行結果の目的を整理する / Organizing objectives of automated test results
twada
PRO
10
2.1k
Some Quick Ideas To Improve Your Tests ( #jassttokyo )
teyamagu
PRO
2
2.3k
Docker ハンズオン / docker-hands-on
suzukihoge
51
16k
document.write再考
brn
5
2.5k
ここ1~2年くらいで 使えるようになった(主要ブラウザーの最新版 がすべて対応した ) ウェブの新機能について ランダムに喋る!
myzkyy
9
6.4k
Laravel OpenAPIによる"辛くない"スキーマ駆動開発
kentaroutakeda
2
2.1k
BuefyのMaintainerを引き継いだ件
kikuomax
0
510
上手な探索的テストとその上達方法について
matsu802
4
650
決断するための勇気、そのためのBacklog / Courage to make decisions, Backlog for that.
seike460
PRO
4
1.9k
実践!RDRAを活用した既存システムの仕様変更 / Specification Changes in Existing Systems Utilizing RDRA
imamotohikaru
0
1.8k
RubyVM を PHP で実装する 〜Hello World を出力するまで〜
memory1994
PRO
1
490
デザインシステムで Tailwind CSSとCSS in JSに分散投資をしたら良かった話
fsubal
14
2.9k
Featured
See All Featured
It's Worth the Effort
3n
180
27k
Teambox: Starting and Learning
jrom
126
8.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
319
23k
Pencils Down: Stop Designing & Start Developing
hursman
115
11k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
185
15k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Why Our Code Smells
bkeepers
PRO
330
56k
A better future with KSS
kneath
230
16k
KATA
mclloyd
14
11k
Infographics Made Easy
chrislema
237
18k
Designing on Purpose - Digital PM Summit 2013
jponch
109
6.4k
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