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
Property Based Testing
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Mathias Verraes
April 06, 2016
Technology
2.8k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Property Based Testing
5min lightning talk for the SoCraTes Belgium meetup and CukeUp London.
Mathias Verraes
April 06, 2016
More Decks by Mathias Verraes
See All by Mathias Verraes
On Being Explicit
mathiasverraes
0
3.1k
How to Find the Bar
mathiasverraes
1
2.2k
Designed Stickiness
mathiasverraes
1
2.3k
The Monty Hall Problem with Haskell
mathiasverraes
0
2.9k
The World's Shortest and Most Chaotic Introduction to Event Storming
mathiasverraes
2
2.8k
Towards Modelling Processes
mathiasverraes
3
6k
Modelling Heuristics
mathiasverraes
1
3.1k
Object Reorientation
mathiasverraes
6
3k
Small Controlled Experiments
mathiasverraes
1
4.3k
Other Decks in Technology
See All in Technology
When Platform Engineering Meets GenAI
sucitw
0
150
SteampipeとExcel Power QueryでAWS構成定義書の作成を自動化する
jhashimoto
0
160
脆弱性対応、どこで線を引くか
rymiyamoto
1
430
WebGIS AI Agentの紹介
_shimizu
0
150
自分が詳しくない領域でAIを使う #プロヒス2026
konifar
20
6.8k
スタートアップにAmazon EKSは早すぎる? マルチプロダクト戦略を加速する Platform Engineeringの実践 / Is Amazon EKS Too Soon for Startups? Practical Platform Engineering to Accelerate a Multi-Product Strategy
elmodev09
1
1.1k
作る力から、見極める力へ — AI時代に広がるエンジニアの価値と役割
rince
0
220
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
440
現地で盛り上がった WWDC26 Keynote
zozotech
PRO
1
270
SONiCのLinuxベースを活かしたZabbix監視
sonic
0
260
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
170
不要なレビューをAIにまかせて AIコーディングの環境改善を加速した
shoota
1
240
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Everyday Curiosity
cassininazir
0
230
KATA
mclloyd
PRO
35
15k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
It's Worth the Effort
3n
188
29k
Facilitating Awesome Meetings
lara
57
7k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
Amusing Abliteration
ianozsvald
1
210
A better future with KSS
kneath
240
18k
Transcript
Property Based Testing @mathiasverraes
None
function inc(x) { return x + 1; }
inc x = x + 1
-- Tests double 1 `should_be` 2 double 2 `should_be` 4
-- Implementation double x | x == 1 = 2 | x == 2 = 4
A property of double double_is_always_even :: Int -> Bool double_is_always_even
x = even (double x)
> quickCheck double_is_always_even Failed: 0 (after 1 test) Exception: Non-exhaustive
patterns in function double
double x = x * 2
quickCheck double_is_always_even Passed: 0 Passed: 1 Passed: -3 Passed: -1
(...) Passed: -58 Passed: 89 +++ OK, passed 100 tests.
More properties of double double_compare_to_input x | x > 0
= double x > x | x < 0 = double x < x | x == 0 = True double_minus_input x = double x - x == x
Distributivity Law reverse_is_distributive xs ys = reverse (xs++ys) == reverse
xs ++ reverse ys
> quickCheck reverse_is_distributive Passed: [] [] Passed: [] [1] Passed:
[1] [] Failed: [3,-3] [0,2,0] Passed: [] [0,2,0] Failed: [3] [0,2,0] Failed: [-3] [0,2,0] Failed: [0] [0,2,0] Failed: [0] [2,0] (...) Falsifiable (after 4 tests and 6 shrinks): [0] [1]
Oops... reverse_is_distributive xs ys = reverse (xs++ys) == reverse ys
++ reverse xs
Passed: [] [] Passed: [1,-2] [0] Passed: [-2] [] (...)
Passed: [-34,44,-58,-41,-17,-53,-14,27,54,46,-10,-46,-20,46] [-9,-32,-47,50,43,-47,-43,-61,37,4,-59,48,34] +++ OK, passed 100 tests.
Split 1 -- define split :: Char -> String ->
[String] -- so that split '@' "
[email protected]
" == ["foo","example.com"] split '/' "/usr/include" == ["", "usr", "include"] 1 https://www.schoolofhaskell.com/user/pbv/an-introduction-to-quickcheck-testing
-- splitting an empty list results in an empty list
split char [] = [] split char str | null after = before : [] | otherwise = before : split char (tail after) where before = takeWhile (/=char) str after = dropWhile (/=char) str
Property: Splitting and unsplitting -- test unsplit '@' ["foo","example.com"] ==
"
[email protected]
" unsplit '/' ["", "usr", "include"] == "/usr/include" --implementation unsplit :: Char -> [String] -> String unsplit char = concat . intersperse [char]
-- property unsplit_inverses_split str = forAll (elements str) (\char ->
unsplit char (split char str) == str)
> quickCheck unsplit_inverses_split Passed: "" Passed: "\252\210" '\252' Passed: "\163^\EOT"
'\163' Passed: "v\RSs" 'v' Failed: "y" 'y' Failed: "a" 'a' Falsifiable (after 6 tests and 1 shrink): "a" 'a'
split 'a' "a" == [""] unsplit 'a' [""] == ""
-- should be: split 'a' "a" == ["", ""] unsplit 'a' ["", ""] == "a"
Modify the definition of split split char [] = []
... -- becomes split char [] = [""] ... > quickCheck unsplit_inverses_split +++ OK, passed 100 tests.
Property Based Testing → test lots of random cases cheaply
→ encourage thinking about general properties Thanks :-) @mathiasverraes