From 920a42b4b55666c582e1d1420336996f4af324fc Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sun, 6 Dec 2020 16:37:19 +0000 Subject: Change answer pritty printer to use CSV-like syntax --- .../sparql/ConjunctiveQueryAnswerSpecs.scala | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/test/scala') diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswerSpecs.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswerSpecs.scala index 65c3e29..ddc6377 100644 --- a/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswerSpecs.scala +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswerSpecs.scala @@ -2,28 +2,38 @@ package uk.ac.ox.cs.rsacomb.sparql import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers -import tech.oxfordsemantic.jrdfox.logic.expression.IRI +import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Variable} object ConjunctiveQueryAnswerSpec { + val varX = Variable.create("X") + val varY = Variable.create("Y") + val varZ = Variable.create("Z") val iri1 = IRI.create("_:iri1") val iri2 = IRI.create("_:iri2") val iri3 = IRI.create("_:iri3") - val oneAnswer = new ConjunctiveQueryAnswers(false, Seq(Seq(iri1, iri2, iri3))) + val oneAnswer = new ConjunctiveQueryAnswers( + false, + Seq(varX, varY, varZ), + Seq(Seq(iri1, iri2, iri3)) + ) val multipleAnswers = new ConjunctiveQueryAnswers( false, + Seq(varY, varZ), Seq(Seq(iri1, iri1), Seq(iri1, iri2), Seq(iri1, iri3)) ) - val noAnswer = new ConjunctiveQueryAnswers(false, Seq()) - val emptyAnswer = new ConjunctiveQueryAnswers(false, Seq(Seq())) + val noAnswer = new ConjunctiveQueryAnswers(false, Seq(), Seq()) + val emptyAnswer = + new ConjunctiveQueryAnswers(false, Seq(varX, varY), Seq(Seq())) - val falseAnswer = new ConjunctiveQueryAnswers(true, Seq()) - val trueAnswer1 = new ConjunctiveQueryAnswers(true, Seq(Seq())) + val falseAnswer = new ConjunctiveQueryAnswers(true, Seq(), Seq()) + val trueAnswer1 = new ConjunctiveQueryAnswers(true, Seq(), Seq(Seq())) val trueAnswer2 = new ConjunctiveQueryAnswers( true, + Seq(varX, varY), Seq(Seq(iri1, iri1), Seq(iri1, iri2), Seq(iri1, iri3)) ) } @@ -32,20 +42,20 @@ class ConjunctiveQueryAnswerSpec extends AnyFlatSpec with Matchers { import ConjunctiveQueryAnswerSpec._ - "A conjunctive query" should "print a single line if it has a single answer" in { - oneAnswer.toString shouldBe s"($iri1, $iri2, $iri3)" + "A conjunctive query" should "print an header and a single line if it has a single answer" in { + oneAnswer.toString shouldBe s"X\tY\tZ\n$iri1\t$iri2\t$iri3" } - it should "print multiple answers on multiple lines" in { - multipleAnswers.toString shouldBe s"($iri1, $iri1)\n($iri1, $iri2)\n($iri1, $iri3)" + it should "print a header and multiple answers on multiple lines" in { + multipleAnswers.toString shouldBe s"Y\tZ\n$iri1\t$iri1\n$iri1\t$iri2\n$iri1\t$iri3" } - it should "print a special \"NO ANSWER\" string when it has no answer" in { - noAnswer.toString shouldBe "NO ANSWER" + it should "print a special \"NO ANSWER.\" string when it has no answer" in { + noAnswer.toString shouldBe "NO ANSWER." } - it should "print an empty list when it has an empty answer" in { - emptyAnswer.toString shouldBe "()" + it should "print only the header when it has an empty answer" in { + emptyAnswer.toString shouldBe "X\tY\n" } "A boolean conjunctive query" should "print \"FALSE\" when it has no answer" in { -- cgit v1.2.3