rustkas

rustkas

Property-Based Testing with PropEr, Erlang, and Elixir:the order of the elements in the comparison expression(page 53)

I’m wondering why you chose the following sequence in your expression:
Function under test =:= reference expression

prop_biggest() ->
    ?FORALL(List, (list(integer())),
            begin
                biggest(List) =:= lists:last(lists:sort(List))
            end).

EUnit macros using assertEqual(Expect, Expr), whehe EUnit uses the opposite order of items.

biggest_test() ->
 ?assert(5 =:= biggest([1, 2, 3, 4, 5])),
 ?assert(8 =:= biggest([3, 8, 7, -1])),
 ?assert(0 =:= biggest([0])), 
 ?assert(5 =:= biggest([-10, 5, -901])).

I understand that the order of the elements doesn’t matter. When you proposed your order, what were you guided by, what were your motives?

Marked As Solved

ferd

ferd

Author of Property-Based Testing with PropEr, LYSE, & Erlang in Anger

That’s an interesting question. I don’t think it’s a super conscious choice, but I tend to use the order of other assertion macros, where for example the format is ?assertMatch(Pattern, Expression) (this is the only one where it’s very sensitive, otherwise you just get the expected/actual order reversed in a report).

I think this, along with pattern matching generally having the assertion left-side, makes me compare that way. For example, many years ago, before people used EUnit macro in common test, the pattern for assertions would have just been Expected = lists:last(lists:sort(List)), Expected = biggest(List) and then letting the est crash if it’s wrong.

In this case, I appear to have swapped the order with what I generally use or would suggest to use, since the model should be driving the test!

Popular Pragmatic Bookshelf topics Top

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
johnp
Hi Brian, Looks like the api for tinydb has changed a little. Noticed while working on chapter 7 that the .purge() call to the db throws...
New
edruder
I thought that there might be interest in using the book with Rails 6.1 and Ruby 2.7.2. I’ll note what I needed to do differently here. ...
New
AleksandrKudashkin
On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New
gilesdotcodes
In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
dtonhofer
@parrt In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New
New

Other popular topics Top

axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
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
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New

Latest in PragProg Customers

View all threads ❯