diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-18 18:27:32 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-18 18:27:32 +0100 |
| commit | c7dbc7c61c7094ea4ec49bd630023f23b92fd9d1 (patch) | |
| tree | 45ff5a535e7d519b58d60c0c214a1f9ecc5a35ef /test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java | |
| parent | 1b6a128137e5d7a6ff75566869232fc054afabef (diff) | |
| download | ACQuA-c7dbc7c61c7094ea4ec49bd630023f23b92fd9d1.tar.gz ACQuA-c7dbc7c61c7094ea4ec49bd630023f23b92fd9d1.zip | |
Configured Maven and improved executable class and tests.
Diffstat (limited to 'test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java')
| -rw-r--r-- | test/uk/ac/ox/cs/pagoda/global_tests/CheckAnswersOverDataset.java | 48 |
1 files changed, 48 insertions, 0 deletions
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 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.global_tests; | ||
| 2 | |||
| 3 | import com.google.gson.Gson; | ||
| 4 | import com.google.gson.reflect.TypeToken; | ||
| 5 | import org.testng.Assert; | ||
| 6 | import uk.ac.ox.cs.pagoda.Pagoda; | ||
| 7 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 8 | |||
| 9 | import java.io.BufferedReader; | ||
| 10 | import java.io.File; | ||
| 11 | import java.io.IOException; | ||
| 12 | import java.lang.reflect.Type; | ||
| 13 | import java.nio.file.Files; | ||
| 14 | import java.nio.file.Path; | ||
| 15 | import java.nio.file.Paths; | ||
| 16 | import java.util.Set; | ||
| 17 | |||
| 18 | /** | ||
| 19 | * Given an instance of Pagoda, it checks the returned answers. | ||
| 20 | * */ | ||
| 21 | public class CheckAnswersOverDataset { | ||
| 22 | |||
| 23 | public static void check(Pagoda pagoda, Path givenAnswers) { | ||
| 24 | try { | ||
| 25 | // Utility.setLogLevel(Level.DEBUG); // uncomment for outputting partial results | ||
| 26 | Path computedAnswers = Paths.get(File.createTempFile("answers", ".json").getAbsolutePath()); | ||
| 27 | new File(computedAnswers.toString()).deleteOnExit(); | ||
| 28 | |||
| 29 | pagoda.run(); | ||
| 30 | assertSameContent(computedAnswers, givenAnswers); | ||
| 31 | } catch (IOException e) { | ||
| 32 | e.printStackTrace(); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | private static void assertSameContent(Path computedAnswersFile, Path givenAnswersFile) throws IOException { | ||
| 37 | BufferedReader computedReader = Files.newBufferedReader(computedAnswersFile); | ||
| 38 | BufferedReader givenReader = Files.newBufferedReader(givenAnswersFile); | ||
| 39 | |||
| 40 | Gson gson = QueryRecord.GsonCreator.getInstance(); | ||
| 41 | |||
| 42 | Type cqType = new TypeToken<Set<QueryRecord>>() {}.getType(); | ||
| 43 | Set<QueryRecord> computedAnswers = gson.fromJson(computedReader, cqType); | ||
| 44 | Set<QueryRecord> givenAnswers = gson.fromJson(givenReader, cqType); | ||
| 45 | |||
| 46 | Assert.assertEquals(computedAnswers, givenAnswers); | ||
| 47 | } | ||
| 48 | } | ||
