aarroyoc / advent-of-code-2020

Solutions of Advent of Code 2020
The Unlicense
7 stars 0 forks source link

Use assertions in the tests? #7

Closed pmoura closed 3 years ago

pmoura commented 3 years ago

Tests such as:

https://github.com/aarroyoc/advent-of-code-2020/blob/b6e92bac83923f648916389ba3f87b77458478cf/test/day1.lgt#L5

can be written using assertions so that a failing test due to the tested predicate returning a wrong value would provide more information. For example:

test(star1, true(X == 988771) :- day1:star(1, X).

If the day1:star/2 predicate is expected to be deterministic, we can write instead:

test(star1, deterministic(X == 988771) :- day1:star(1, X).

In case of test failure, the X == 988771 assertion is printed, potentially providing valuable information for debugging.

aarroyoc commented 3 years ago

Thanks for the suggestions! I'm not going to force "deterministic" yet because I have some flaky code. I'm also very new to the whole Logtalk ecosystem.