rustkas

rustkas

Property-Based Testing with PropEr, Erlang, and Elixir: Finding a simplified case of inconsistency (page 146)

I noticed that the necessary inconsistence, which describes in an example PropEr framework does not find a discrepancy in the RFC 4180 specification, is far from at once. I was surprised when I ran the property several times and didn’t get the error I was looking for.

$ rebar3 proper
===> Testing prop_csv:prop_roundtrip()
....................................................................................................
OK: Passed 100 test(s).
===>
1/1 properties passed

When I increased the number of tests to 1000, the framework reproduced the necessary use case.

$ rebar3 proper -n 1000
===> Testing prop_csv:prop_roundtrip()
..........................!
Failed: After 27 test(s).
[#{[40,36] => []},#{[40,36] => []}]

Shrinking .......(7 time(s))
[#{[66,65] => []},#{[66,65] => []}]
===>
0/1 properties passed, 1 failed
===> Failed test cases:
prop_csv:prop_roundtrip() -> false

PropEr can help us in it better. As we know about a possible problem we can narrow Size to 1. For this task we can add simplified generator and property-based test:

%%%%%%%%%%%%%%%%%%
%%% Properties %%%
%%%%%%%%%%%%%%%%%%
prop_roundtrip_01() ->
    ?FORALL(Maps,
            csv_source_01(),
            Maps
            =:= bday_csv:decode(
                    bday_csv:encode(Maps))).

%%%%%%%%%%%%%%%%%%
%%% Generators %%%
%%%%%%%%%%%%%%%%%%

csv_source_01() ->
    ?LET(Keys, header(1), list(entry(1, Keys))).

Launching that property we get the expected error has gotten every time:

$ rebar3 proper -d apps/bday/test -p prop_roundtrip_01
===> Linking _build/default/plugins/rebar3_format to _build/test/plugins/rebar3_format
===> Linking _build/default/plugins/katana_code to _build/test/plugins/katana_code
===> Verifying dependencies...
===> Linking _build/default/plugins/covertool to _build/test/plugins/covertool
===> Compiling bday
===> Testing prop_csv:prop_roundtrip_01()
.......!
Failed: After 8 test(s).
[#{[125] => [75,85,50]},#{[125] => []},#{[125] => []}]

Shrinking ......(6 time(s))
[#{[65] => []},#{[65] => []}]
===>
0/1 properties passed, 1 failed
===> Failed test cases:
prop_csv:prop_roundtrip_01() -> false

Popular Prag Prog topics Top

New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
digitalbias
Title: Build a Weather Station with Elixir and Nerves: Problem connecting to Postgres with Grafana on (page 64) If you follow the defau...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
rainforest
Hi, I’ve got a question about the implementation of PubSub when using a Phoenix.Socket.Transport behaviour rather than channels. Before ...
New
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
New
EdBorn
Title: Agile Web Development with Rails 7: (page 70) I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New

Other popular topics Top

AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New

Latest in PragProg

View all threads ❯