From 7d06969bd58124931b87e9933198be5bda8c2c6a Mon Sep 17 00:00:00 2001 From: Vanessa Teague Date: Mon, 10 Jun 2024 09:19:34 +1000 Subject: [PATCH] Corrected tests; moved num_candidates into raire solution. --- .../response/RaireResultMixIn.java | 11 ---------- .../controller/GetAssertionsAPIJsonTests.java | 4 ++-- ...ssertionsInProgressAPIJsonAndCsvTests.java | 9 +++++--- .../GetAssertionsServiceJsonTests.java | 10 +++++++-- .../raireservice/testUtils.java | 22 ++++++++++--------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/au/org/democracydevelopers/raireservice/response/RaireResultMixIn.java b/src/main/java/au/org/democracydevelopers/raireservice/response/RaireResultMixIn.java index 905a209..a67c075 100644 --- a/src/main/java/au/org/democracydevelopers/raireservice/response/RaireResultMixIn.java +++ b/src/main/java/au/org/democracydevelopers/raireservice/response/RaireResultMixIn.java @@ -33,17 +33,6 @@ the raire assertion generation engine (https://github.com/DemocracyDevelopers/ra */ public class RaireResultMixIn extends RaireResult { - /** - * The winner of an IRV contest is not stored in the colorado-rla database. - @JsonIgnore public int winner; - */ - - /** - * raire-service includes the candidates of a contest in the metadata attached to a RaireSolution. - * FIXME should we include this after all? - */ - @JsonIgnore public int num_candidates; - /** * The time that raire-java takes to determine the winner of an IRV contest is not stored in * the colorado-rla database. diff --git a/src/test/java/au/org/democracydevelopers/raireservice/controller/GetAssertionsAPIJsonTests.java b/src/test/java/au/org/democracydevelopers/raireservice/controller/GetAssertionsAPIJsonTests.java index 23629a6..e65427f 100644 --- a/src/test/java/au/org/democracydevelopers/raireservice/controller/GetAssertionsAPIJsonTests.java +++ b/src/test/java/au/org/democracydevelopers/raireservice/controller/GetAssertionsAPIJsonTests.java @@ -138,7 +138,7 @@ void retrieveAssertionsExistentContestOneNEBAssertion() { assertNull(response.getBody().solution.Err); // Check the contents of the RaireResults within the RaireSolution. - assertTrue(correctSolutionData(320,1.1, 1, response.getBody().solution.Ok)); + assertTrue(correctSolutionData(320,1.1, 2,1, 1, response.getBody().solution.Ok)); // We expect one NEB assertion with the following data. assertTrue(correctAssertionData("NEB", 320, 1.1, 0, @@ -167,7 +167,7 @@ void retrieveAssertionsExistentContestOneNENAssertion() { assertNull(response.getBody().solution.Err); // Check the contents of the RaireResults within the RaireSolution. - assertTrue(correctSolutionData(240, 3.01, 1, response.getBody().solution.Ok)); + assertTrue(correctSolutionData(240, 3.01, 4, 0, 1, response.getBody().solution.Ok)); // We expect one NEN assertion with the following data. assertTrue(correctAssertionData("NEN",240,3.01, 0, diff --git a/src/test/java/au/org/democracydevelopers/raireservice/controller/GetAssertionsInProgressAPIJsonAndCsvTests.java b/src/test/java/au/org/democracydevelopers/raireservice/controller/GetAssertionsInProgressAPIJsonAndCsvTests.java index a063a3c..2840107 100644 --- a/src/test/java/au/org/democracydevelopers/raireservice/controller/GetAssertionsInProgressAPIJsonAndCsvTests.java +++ b/src/test/java/au/org/democracydevelopers/raireservice/controller/GetAssertionsInProgressAPIJsonAndCsvTests.java @@ -118,7 +118,8 @@ void retrieveAssertionsExistentContestOneNEBAssertionJSON() { assertNull(response.getBody().solution.Err); // Check the contents of the RaireResults within the RaireSolution. - assertTrue(correctSolutionData(320,1.1, 1, + // FIXME + assertTrue(correctSolutionData(320,1.1, 2,1, 1, response.getBody().solution.Ok)); // We expect one NEB assertion with the following data. @@ -184,7 +185,8 @@ void retrieveAssertionsExistentContestOneNENAssertionJSON() { assertNull(response.getBody().solution.Err); // Check the contents of the RaireResults within the RaireSolution. - assertTrue(correctSolutionData(240, 3.01, 1, + // FIXME + assertTrue(correctSolutionData(240, 3.01, 4, 3, 1, response.getBody().solution.Ok)); // We expect one assertion with the following data. @@ -255,7 +257,8 @@ void retrieveAssertionsOneNENOneNEBAssertionInProgressJSON() { assertNull(response.getBody().solution.Err); // Check the contents of the RaireResults within the RaireSolution. - assertTrue(correctSolutionData(112, 3.17, 2, + //FIXME + assertTrue(correctSolutionData(112, 3.17, 4, 3, 2, response.getBody().solution.Ok)); // We expect two assertions with the following data, but we don't necessarily know what order diff --git a/src/test/java/au/org/democracydevelopers/raireservice/service/GetAssertionsServiceJsonTests.java b/src/test/java/au/org/democracydevelopers/raireservice/service/GetAssertionsServiceJsonTests.java index 9a0d2ac..4543d33 100644 --- a/src/test/java/au/org/democracydevelopers/raireservice/service/GetAssertionsServiceJsonTests.java +++ b/src/test/java/au/org/democracydevelopers/raireservice/service/GetAssertionsServiceJsonTests.java @@ -80,7 +80,7 @@ void retrieveAssertionsExistentContestOneNEBAssertion() throws RaireServiceExcep testUtils.log(logger, "retrieveAssertionsExistentContestOneNEBAssertion"); GetAssertionsJsonService service = new GetAssertionsJsonService(assertionRepository); GetAssertionsRequest request = new GetAssertionsRequest("One NEB Assertion Contest", - defaultCount, List.of("Alice", "Bob"), defaultWinner, BigDecimal.valueOf(0.1)); + defaultCount, List.of("Alice", "Bob"), "Bob", BigDecimal.valueOf(0.1)); RaireSolution solution = service.getRaireSolution(request); @@ -94,6 +94,8 @@ void retrieveAssertionsExistentContestOneNEBAssertion() throws RaireServiceExcep // Check the contents of the RaireResults within the RaireSolution. assertEquals(1.1, solution.solution.Ok.difficulty); assertEquals(320, solution.solution.Ok.margin); + assertEquals(1, solution.solution.Ok.winner); + assertEquals(2, solution.solution.Ok.num_candidates); AssertionAndDifficulty[] assertions = solution.solution.Ok.assertions; assertEquals(1, assertions.length); @@ -119,7 +121,8 @@ void retrieveAssertionsExistentContestOneNENAssertion() throws RaireServiceExcep testUtils.log(logger, "retrieveAssertionsExistentContestOneNENAssertion"); GetAssertionsJsonService service = new GetAssertionsJsonService(assertionRepository); GetAssertionsRequest request = new GetAssertionsRequest("One NEN Assertion Contest", - defaultCount, List.of("Alice", "Charlie", "Diego", "Bob"), defaultWinner, BigDecimal.valueOf(0.1)); + defaultCount, List.of("Alice", "Charlie", "Diego", "Bob"), "NotACandidate", + BigDecimal.valueOf(0.1)); RaireSolution solution = service.getRaireSolution(request); @@ -134,6 +137,9 @@ void retrieveAssertionsExistentContestOneNENAssertion() throws RaireServiceExcep // Check the contents of the RaireResults within the RaireSolution. assertEquals(3.01, solution.solution.Ok.difficulty); assertEquals(240, solution.solution.Ok.margin); + // Winner is -1 if not a candidate. This should be caught at request validation. + assertEquals(-1, solution.solution.Ok.winner); + assertEquals(4, solution.solution.Ok.num_candidates); AssertionAndDifficulty[] assertions = solution.solution.Ok.assertions; assertEquals(1, assertions.length); diff --git a/src/test/java/au/org/democracydevelopers/raireservice/testUtils.java b/src/test/java/au/org/democracydevelopers/raireservice/testUtils.java index 60314c2..3b9a9c0 100644 --- a/src/test/java/au/org/democracydevelopers/raireservice/testUtils.java +++ b/src/test/java/au/org/democracydevelopers/raireservice/testUtils.java @@ -113,19 +113,21 @@ public static boolean correctMetadata(List candidates, String contestNam /** * Check that the RaireResult's solution has the expected margin and difficulty. - * @param margin expected margin - * @param difficulty expected difficulty - * @param numAssertions the expected number of assertions - * @param result the RaireResult in the body of the response + * @param margin expected margin. + * @param difficulty expected difficulty. + * @param numCandidates the number of candidates. + * @param winner the winner's index in the candidate array. + * @param numAssertions the expected number of assertions. + * @param result the RaireResult in the body of the response. * @return true if the result's data matches the expected values. */ - public static boolean correctSolutionData(int margin, double difficulty, int numAssertions, - RaireResult result) { + public static boolean correctSolutionData(int margin, double difficulty, int numCandidates, + int winner, int numAssertions, RaireResult result) { - int retrievedMargin = result.margin; - double retrievedDifficulty = result.difficulty; - return retrievedMargin == margin - && doubleComparator.compare(retrievedDifficulty, difficulty) == 0 + return result.margin == margin + && doubleComparator.compare(result.difficulty, difficulty) == 0 + && result.num_candidates == numCandidates + && result.winner == winner && result.assertions.length == numAssertions; }