Improving assertions in Erlang's Bank Account and Circular Buffer tests

Just wanted to check before raising a PR… The Bank Account and Circular Buffer exercises in the Erlang track are using the ?assert(Expr =:= Expect) assertion style. I think it would be better to use ?assertEqual(Expect, Expr) because the assertion error explains what it expected vs what it got.

For example, the assertion ?assert(Amount =:= 2) gives the error message:

**error:{assert,[{module,bank_account_tests},
         {line,67},
         {expression,"Amount =:= 2"},
         {expected,true},
         {value,false}]}

From this one, its hard to see what Amount was. Whereas ?assertEqual(10, Amount) gives:

**error:{assertEqual,[{module,bank_account_tests},
              {line,67},
              {expression,"Amount"},
              {expected,2},
              {value,0}]}

I’d be happy to raise a PR if there is agreement with this change.

cc @NobbZ

1 Like

Not the Erlang maintainer, but for what it’s worth, the proposed change is also how we do it on the Lisp Flavoured Erlang track (as (is-equal 2 amount)). It helps makes what we’re comparing more explicit.

IIRC assertEqual does an equality check (==) rather than a match (=:=) and we want integers here, not floats.

Though indeed, I would appreciate a PR that switches to assertMatch/assertMatches (don’t remember).

1 Like

PR raised Use assertMatch instead of assert by kahgoh · Pull Request #606 · exercism/erlang · GitHub