Commit e063833e authored by Martin Spoto's avatar Martin Spoto
Browse files

Finished unit test for clauses; more verbose output for tests

parent 19eabe0e
......@@ -284,6 +284,8 @@ public class ProloGraalTestRunner extends ParentRunner<TestCase> {
Assert.assertEquals(input.length, linesPerInput.size()-1); // -1 for the "yes" produced while exiting
Assert.assertEquals(linesPerInput.size(), expectedLinesForInput.size());
List<String> errors = new ArrayList<>();
for (int i = 0; i < linesPerInput.size(); i++) {
List<String> actualLines = linesPerInput.get(i);
List<String> expectedLines = expectedLinesForInput.get(i);
......@@ -296,11 +298,25 @@ public class ProloGraalTestRunner extends ParentRunner<TestCase> {
msg = "EOF";
}
Assert.assertEquals(msg, expectedLines.size(), actualLines.size());
if(expectedLines.size() != actualLines.size()) {
String errorMsg = "Output does not have expected size for input \"" +
msg +
"\"\nExpected : \n" +
expectedLines.stream().map(x -> "\t" + x).collect(Collectors.joining("\n")) +
"\nActual : \n" +
actualLines.stream().map(x -> "\t" + x).collect(Collectors.joining("\n")) +
"\n";
System.err.println(errorMsg);
errors.add(errorMsg);
continue;
}
for(int j = 0; j < actualLines.size(); j++) {
Assert.assertEquals(msg, expectedLines.get(j), actualLines.get(j));
}
}
if(!errors.isEmpty()) {
throw new AssertionError(errors.get(0));
}
} catch (Throwable ex) {
notifier.fireTestFailure(new Failure(testCase.name, ex));
......
......@@ -4,4 +4,13 @@ test(a, B).
test(X, X).
listConcat([a, b], [c,d], [a,b,c,d]).
listConcat([a, b], X, [a,b,c,d]).
listConcat(X, [c,d], [a,b,c,d]).
\ No newline at end of file
listConcat(X, [c,d], [a,b,c,d]).
concatDL('-'([a, b, c | Xs], Xs), '-'([d, e, f | Ys], Ys), R).
listSuffix([a,b,c], [b,c]).
listRightTrim([a,b,c], X).
listPrefix([a,b,c], [a,b]).
owns([a,b,c,d,e,f], d).
owns([a,b,c,d,e,f], g).
listSublist1([a,b,c,d,e], [b,c,d]).
listSublist1([a,b,c,d,e], [b,c,X]).
unifyMany([a,b,C,D,f(E)], [a,b,c,D,f(e)]).
\ No newline at end of file
% test(a, b).
yes
% test(A, B).
A = a
B = b
yes
% test(a, B).
B = b
yes
% test(X, X).
no
% listConcat([a, b], [c,d], [a,b,c,d]).
yes
% listConcat([a, b], X, [a,b,c,d]).
X = [c, d]
yes
% listConcat(X, [c,d], [a,b,c,d]).
X = [a, b]
yes
% concatDL('-'([a, b, c | Xs], Xs), '-'([d, e, f | Ys], Ys), R).
R = '-'([a, b, c, d, e, f | Ys], Ys)
Xs = [d, e, f | Ys]
yes
% listSuffix([a,b,c], [b,c]).
yes
% listRightTrim([a,b,c], X).
X = [a, b]
yes
% listPrefix([a,b,c], [a,b]).
yes
% owns([a,b,c,d,e,f], d).
yes
% owns([a,b,c,d,e,f], g).
no
% listSublist1([a,b,c,d,e], [b,c,d]).
yes
% listSublist1([a,b,c,d,e], [b,c,X]).
X = d
yes
% unifyMany([a,b,C,D,f(E)], [a,b,c,D,f(e)]).
C = c
E = e
yes
% EOF
yes
\ No newline at end of file
......@@ -26,9 +26,6 @@ listConcat([], A, A).
listConcat([X | Xs], Ys, [X | Rs]) :-
listConcat(Xs, Ys, Rs).
listConcat2(Xs, Ys, Rs) :-
append(Xs, Ys, Rs).
% --- listSuffix(+L, ?S) : S is a suffix of L
listSuffix(L, L).
......@@ -59,15 +56,6 @@ listSublist1(Ls, Ss) :-
listSuffix(Ps, Ss),
listPrefix(Ls, Ps).
% ----------------------
listSublist2(Ls, Ss) :-
listPrefix(Ls, Ps),
listSuffix(Ps, Ss).
% ----------------------
listSublist3(Ls, Ss) :-
listSuffix(Ls, Sufs),
listPrefix(Sufs, Ss).
%----------- S02 - Ex 6) ---------------------
......@@ -75,10 +63,3 @@ listSublist3(Ls, Ss) :-
% and each Aj is unified with Bj
unifyMany(A, A).
%unifyMany2(A, B) :-
% A = B. % not working for now because of the = operator
unifyMany3([], []).
unifyMany3([X | Xs], [X | Ys]) :-
unifyMany3(Xs, Ys).
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment