Commit 19eabe0e authored by Martin Spoto's avatar Martin Spoto
Browse files

Improved unit test logic and fixed some of them

parent 12d0f054
......@@ -17,12 +17,10 @@ import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
......@@ -243,7 +241,7 @@ public class ProloGraalTestRunner extends ParentRunner<TestCase> {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
context = Context.newBuilder().in(new ByteArrayInputStream(testCase.testInput.getBytes("UTF-8"))).out(out).build();
context = Context.newBuilder().in(new ByteArrayInputStream(testCase.testInput.getBytes(StandardCharsets.UTF_8))).out(out).build();
PrintWriter printer = new PrintWriter(out);
run(context, testCase.path, printer);
printer.flush();
......@@ -251,16 +249,59 @@ public class ProloGraalTestRunner extends ParentRunner<TestCase> {
String actualOutput = new String(out.toByteArray());
String[] input = testCase.testInput.split("\\R");
String[] actual = actualOutput.split("\\R");
String[] expected = testCase.expectedOutput.split("\\R");
Assert.assertEquals("Expected and actual ouputs differ in length !", expected.length, actual.length);
List<List<String>> linesPerInput;
linesPerInput =
Arrays.stream(actualOutput.split("\\?- "))
.filter(s -> !s.isEmpty())
.map(s -> s.split("\\R"))
.map(Arrays::asList)
.map(x -> x.stream()
.filter(s -> !s.isEmpty())
.collect(Collectors.toList()))
.collect(Collectors.toList());
List<List<String>> expectedLinesForInput;
expectedLinesForInput =
Arrays.stream(testCase.expectedOutput.split("%.*\\R"))
.skip(1)
.map(x -> x.split("\\R"))
.map(Arrays::asList)
.collect(Collectors.toList());
System.out.println("-----" + testCase.name + "-----");
System.out.println();
System.out.println();
System.out.println("----- EXPECTED -----");
System.out.println(expectedLinesForInput);
System.out.println();
System.out.println("----- ACTUAL -----");
System.out.println(linesPerInput);
System.out.println();
System.out.println();
Assert.assertEquals(input.length, linesPerInput.size()-1); // -1 for the "yes" produced while exiting
Assert.assertEquals(linesPerInput.size(), expectedLinesForInput.size());
for (int i = 0; i < linesPerInput.size(); i++) {
List<String> actualLines = linesPerInput.get(i);
List<String> expectedLines = expectedLinesForInput.get(i);
String msg;
if(i < linesPerInput.size()-1) {
msg = input[i];
} else {
msg = "EOF";
}
System.out.println(Arrays.toString(input));
System.out.println(Arrays.toString(actual));
System.out.println(Arrays.toString(expected));
Assert.assertEquals(msg, expectedLines.size(), actualLines.size());
for(int j = 0; j < actualLines.size(); j++) {
Assert.assertEquals(msg, expectedLines.get(j), actualLines.get(j));
}
}
Assert.assertArrayEquals("Expected and actual outputs are different", expected, actual);
} catch (Throwable ex) {
notifier.fireTestFailure(new Failure(testCase.name, ex));
} finally {
......
?- yes
?- Error : no clause for goal 'fact2'
?- Error : no clause for goal 'fact/1([X])'
?- yes
?- yes
?- no
?- yes
?- no
?- yes
?- yes
?- no
?- yes
?- Error : no clause for goal 'fact/1([world])'
?- yes
\ No newline at end of file
% fact.
yes
% fact2.
Error : no clause for goal 'fact2:-.'
% fact(X).
Error : no clause for goal 'fact/1(X):-.'
% hello(world).
yes
% hello(world2).
yes
% hello(world3).
no
% multiples(arg1, arg2).
yes
% multiples(arg1, arg3).
no
% 'this is also'('a fact').
yes
% numbers(test, 42, 21.21).
yes
% numbers(test, 42, 21.2121).
no
% this(is(getting, a(bit(out, of, hand)))).
yes
% fact(world).
Error : no clause for goal 'fact/1(world):-.'
% EOF
yes
......@@ -14,4 +14,4 @@ multiple(X, b, a).
nested(X, one(Y, two(three(a)))).
f(B, h(A)).
indirection(A, B, C, x).
%occurs(X, X).
\ No newline at end of file
% occurs(X, X). TODO enable with when occurs check is fixed
\ No newline at end of file
?- yes
?- yes
?- yes
?- yes
?- Y = a
Y = b
Y = c
% fact(a).
yes
% fact(b).
yes
% fact(X).
yes
% multifacts(a).
yes
% multifacts(Y).
Y = a
yes
?- X = a
% multiargs(X, Y).
X = a
Y = b
X = c
Y = d
yes
?- yes
?- X = world
% hello(world, a).
yes
% hello(X, a).
X = world
yes
% hello(X, Y).
X = world
yes
% multiple(a, b, c).
no
% multiple(a, b, a).
yes
% multiple(a, b, X).
X = a
yes
?- X = world
% multiple(X, b, a).
X = a
yes
?- no
?- yes
?- X = a
% nested(X, one(Y, two(three(a)))).
X = a
yes
?- X = a
% f(B, h(A)).
yes
?- X = a
% indirection(A, B, C, x).
A = x
B = x
C = x
yes
?- yes
?- yes
\ No newline at end of file
% occurs(X, X).
no
% EOF
yes
\ No newline at end of file
test([a, b, c, d]).
test([a, b, c, d | []]).
test([a, b | [c, d]]).
test('.'(a, '.'(b, '.'(c, '.'(d, []))))).
test([a, b | Xs]).
test([Head | Tail]).
test([a, B, C, d]).
test([a, B, C | Tail]).
unify([a,b,c], X).
unify(X, [a,b,c]).
unify([a | Xs], [a,b,c | Ys]).
\ No newline at end of file
% test([a, b, c, d]).
yes
% test([a, b, c, d | []]).
yes
% test([a, b | [c, d]]).
yes
% test('.'(a, '.'(b, '.'(c, '.'(d, []))))).
yes
% test([a, b | Xs]).
Xs = [c, d]
yes
% test([Head | Tail]).
Head = a
Tail = [b, c, d]
yes
% test([a, B, C, d]).
B = b
C = c
yes
% test([a, B, C | Tail]).
B = b
C = c
Tail = [d]
yes
% unify([a,b,c], X).
X = [a, b, c]
yes
% unify(X, [a,b,c]).
X = [a, b, c]
yes
% unify([a | Xs], [a,b,c | Ys]).
Xs = [b, c | Ys]
yes
% EOF
yes
\ No newline at end of file
test([a, b, c, d]).
unify(A, A).
\ No newline at end of file
......@@ -2,7 +2,6 @@ test(a, b).
test(A, B).
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
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