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

jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
New
jeremyhuiskamp
Title: Web Development with Clojure, Third Edition, vB17.0 (p9) The create table guestbook syntax suggested doesn’t seem to be accepted ...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
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
kolossal
Hi, I need some help, I’m new to rust and was learning through your book. but I got stuck at the last stage of distribution. Whenever I t...
New
Henrai
Hi, I’m working on the Chapter 8 of the book. After I add add the point_offset, I’m still able to see acne: In the image above, I re...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New

Other popular topics Top

AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
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
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
PragmaticBookshelf
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
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
AstonJ
This is a very quick guide, you just need to: Download LM Studio: https://lmstudio.ai/ Click on search Type DeepSeek, then select the o...
New

Latest in PragProg

View all threads ❯