-
Notifications
You must be signed in to change notification settings - Fork 141
Add Prolog Support #159
Comments
Swi prolog has its own testing framework package known as plunit |
Does it support custom output? |
You mean like writing to the console? |
No, we need test results in Codewars format:
Some test frameworks provides a way to add custom reporter. |
I think that you should write that format as output like in:
where write is pretty much the equivalent of |
Regarding that the test unit framework says
|
I think you're misunderstanding. |
So this example from the documentation test(add) :-
A is 1 + 2,
A =:= 3. needs to output |
Another options is to derive the Codewars output from its test results. For PowerShell, we generate Codewars format from NUnit XML report. The last resort is to parse its output and try our best to generate compatible result. We currently do this for Rust. |
rules are evaluated sequentially, so in
it will print
in the fail may have some error messages according the error. And your example translated will be:
That as you may think resembles current erlang code style, if one rule doesn't match the input it will try the next allowing recursive definitions and rewriting of simple rules. |
I tried your suggestion :- begin_tests(example).
error:-write('<ERROR::>'),nl,fail.
passed:-write('<PASSED::>'),nl.
test(add) :-
A is 1 + 2,
A =:= 3,
passed .
test(add) :-
A \= 3,
error .
:- end_tests(example). and got
Everything except |
I've asked in the English StackOverflow and Spanish StackOverflow sites in order to integrate it with the default unit test framework. I'll update later. |
How does the regular output of |
Sucessfull:
Unsucessfull:
|
What people said in the StackOverflow was that I could try to run a query with something like Successful
Unsuccessful
But my concern is that this could implicate not using the standard test framework. If you think it's the more viable option I can try creating a rule doing queries like that, something like
so the unit test could be written something like:
|
I'd like to avoid that if possible. I think we should look for another option if I was reading their docs and found the section for Failing Example: % test.pl
:- begin_tests(test).
test(a) :-
A is 2^3,
assertion(float(A)),
assertion(A == 9).
:- end_tests(test).
Passing Example: % test.pl
:- begin_tests(test).
test(a) :-
A is 2^3,
assertion(A == 8).
:- end_tests(test).
Running Tests: # `-g true` to suppress welcome message.
swipl -g true -t 'run_tests.' -s test.pl For tests in separate file, do: # tests in example.plt
swipl -g true -t "load_test_files([]), run_tests." -s example.pl |
I think I can do the following (assuming the failure messages are always well formatted):
Files: % solution.pl
add_3_and_double(X,Y) :- Y is (X+3)*3. % solution.plt
:- begin_tests(solution).
:- include(solution).
test(test_add_3_and_double_1) :-
add_3_and_double(1, X),
assertion(float(X)),
assertion(X == 8).
test(test_add_3_and_double_2) :-
add_3_and_double(2, X),
X == 10.
test(test_add_3_and_double_3) :-
add_3_and_double(-3, X),
X == 0.
:- end_tests(solution). Run tests:
(don't know where "A. done" comes from and seems inconsistent) Post-processed:
@javatlacati, @flip111, @razvan-flavius-panda, @Radivarig, @Kinrany What do you think? Can any of you provide some example challenge for me to play with? |
Could it be a concurrency issue, with multiple messages being printed at the same time?
Would the recursive Euclid algorithm be a good enough example? |
I think When I change the second test to use assertion, the output changes to:
When all 3 tests pass, the output is:
It looks weird, but it makes sense now.
I'm looking for different ways to fail the test to observe the outputs and adjust the post processing as needed. So it'll be really helpful if you can come up with some tests and different examples of failures for them. |
It looks like it's printing both "A" and the error message in parallel, and "done" is just the end of enumeration. Maybe the error messages can be suppressed or redirected, so you can get an easy to parse "solution AA. done"?
Like this? test(test_gcd_1) :-
gcd(2, 3, 1).
test(test_gcd_2) :-
gcd(4, 6, 2).
test(test_gcd_3) :-
forall(gcd(4, 6, X), X is 2). Disclaimer: I barely know anything about Prolog, I upvoted because I'd like to learn it :) |
Deployed Prolog support. |
Hope this could help for the error messages: addition.pl
addition_ut.pl
Interactive run
|
Some good edimburg prolog will be nice!
What about some open-source SWI-Prolog?
The text was updated successfully, but these errors were encountered: