-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prolog: Codewars runner can't handle assertions that produce better failure message #297
Comments
Check if you can use patterns from my collection of authoring examples: (Credits to |
Thanks for the suggested workaround. I'll use it in https://www.codewars.com/kata/trilingual-democracy/prolog. It's a bit cumbersome. For example, I have to use Tests = [
(group = "DDD")-(expected = 'D'),
(group = "DDF")-(expected = 'F'),
(group = "DDI")-(expected = 'I'),
...
], instead of Tests = [
"DDD"-'D',
"DDF"-'F',
"DDI"-'I',
...
], But for now that seemed acceptable. I'd rather have bloated code that produces better failure messages than compact code and confusing messages. Of course, that's just a workaround, not really a fix for the problem. Also, the failure messages are better, but there's room for improvement. The message |
|
@error256 I don't quite understand how it works, but the |
He is right though, |
Oh, I see what you mean. To catch that pathological case, we'll have to use I just meant to say that the |
I played with the workaround mentioned above a bit more. Two improvements that work well for my case and may also work for others: 1. Lists of tests don't need the cumbersome syntax. 2. Failure messages also show actual value. sample_tests(Test) :-
Pairs = [
"FFF"-'F',
"IIK"-'K',
"DFK"-'I'
],
as_tests(Pairs, Test).
random_tests(Test) :-
Pairs = [
"DDD"-'D',
...
"KKK"-'K'
],
random_permutation(Pairs, Permutation),
as_tests(Permutation, Test).
as_tests(Pairs, Test) :-
member(Group-Expected, Pairs),
(trilingual_democracy(Group, Result) -> Actual = Result; Actual = undefined), % predicate under test
Test = (group = Group)-(expected = Expected)-(actual = Actual).
do_test(expected = Expected, actual = Actual) :-
assertion(Expected == Actual).
test(sample_tests, forall(sample_tests(_-Expected-Actual))) :-
do_test(Expected, Actual).
In the EDIT: The original version of the code above had this line: trilingual_democracy(Group, Actual), This meant that even (trilingual_democracy(Group, Result) -> Actual = Result; Actual = undefined), I hope the tests now catch all pathological cases... |
The PlUnit documentation at https://www.swi-prolog.org/pldoc/man?section=testbody sounds like |
Describe the bug
I tried to use assertions that lead to better failure messages:
Expected 'X' Got 'Y'
instead of justAssertion: 'X' == 'Y'
.I followed the instructions given in this Stack Overflow answer. The code produces the output I wanted, but the Codewars runner doesn't display it properly, and even seems to mark the test as passed.
To Reproduce
Old code: Produces
Assertion: 'X' == 'Y'
on failure. Not very helpful, not clear which one is the expected / actual value.New code: Produces
Expected 'X' Got 'Y'
on failure, but the Codewars runner doesn't recognize it.Expected behavior
The Codewars runner should recognize the better failure messages (
Expected 'X' Got 'Y'
instead ofAssertion: 'X' == 'Y'
) and show them in the usual way. And the runner should mark the test as failed.Screenshots
New code: Good failure messages, but the Codewars runner doesn't display them properly, and it doesn't quite recognize that the test failed:
Old code: Codewars runner displays failure messages in the correct way and recognizes that the test failed, but the messages are not very helpful, because they don't distinguish between expected and actual value.
The text was updated successfully, but these errors were encountered: