From c7dbc7c61c7094ea4ec49bd630023f23b92fd9d1 Mon Sep 17 00:00:00 2001 From: RncLsn Date: Mon, 18 May 2015 18:27:32 +0100 Subject: Configured Maven and improved executable class and tests. --- .../global_tests/CheckAnswersOverDataset.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java (limited to 'test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java') diff --git a/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java b/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java new file mode 100644 index 0000000..424afa2 --- /dev/null +++ b/test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java @@ -0,0 +1,48 @@ +package uk.ac.ox.cs.pagoda.global_tests; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import org.testng.Assert; +import uk.ac.ox.cs.pagoda.Pagoda; +import uk.ac.ox.cs.pagoda.query.QueryRecord; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Set; + +/** + * Given an instance of Pagoda, it checks the returned answers. + * */ +public class CheckAnswersOverDataset { + + public static void check(Pagoda pagoda, Path givenAnswers) { + try { +// Utility.setLogLevel(Level.DEBUG); // uncomment for outputting partial results + Path computedAnswers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); + new File(computedAnswers.toString()).deleteOnExit(); + + pagoda.run(); + assertSameContent(computedAnswers, givenAnswers); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void assertSameContent(Path computedAnswersFile, Path givenAnswersFile) throws IOException { + BufferedReader computedReader = Files.newBufferedReader(computedAnswersFile); + BufferedReader givenReader = Files.newBufferedReader(givenAnswersFile); + + Gson gson = QueryRecord.GsonCreator.getInstance(); + + Type cqType = new TypeToken>() {}.getType(); + Set computedAnswers = gson.fromJson(computedReader, cqType); + Set givenAnswers = gson.fromJson(givenReader, cqType); + + Assert.assertEquals(computedAnswers, givenAnswers); + } +} -- cgit v1.2.3