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 Prag Prog topics Top

New
belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
New
dachristenson
@mfazio23 Android Studio will not accept anything I do when trying to use the Transformations class, as described on pp. 140-141. Googl...
New

Other popular topics Top

DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1122 25133 743
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New

Latest in PragProg

View all threads ❯