diff --git a/src/test/java/au/org/democracydevelopers/raireservice/service/GenerateAssertionsOnKnownTests.java b/src/test/java/au/org/democracydevelopers/raireservice/service/GenerateAssertionsOnKnownTests.java index 3c4007c..c50d3a7 100644 --- a/src/test/java/au/org/democracydevelopers/raireservice/service/GenerateAssertionsOnKnownTests.java +++ b/src/test/java/au/org/democracydevelopers/raireservice/service/GenerateAssertionsOnKnownTests.java @@ -22,7 +22,6 @@ the raire assertion generation engine (https://github.com/DemocracyDevelopers/ra import static au.org.democracydevelopers.raireservice.testUtils.correctDBAssertionData; -import static au.org.democracydevelopers.raireservice.testUtils.correctAssumedContinuing; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -127,7 +126,7 @@ void NEBassertionRetrievalWorks() { Assertion assertion = assertionRepository.findByContestName(oneNEBAssertionContest).getFirst(); assertInstanceOf(NEBAssertion.class, assertion); assertTrue(correctDBAssertionData(320, 0.32, 1.1, "Alice", - "Bob", assertion)); + "Bob", List.of(), assertion)); } @@ -141,8 +140,7 @@ void NENassertionRetrievalWorks() { Assertion assertion = assertionRepository.findByContestName(oneNENAssertionContest).getFirst(); assertTrue(correctDBAssertionData(20, 0.4, 2.5, "Alice", - "Bob", assertion)); - assertTrue(correctAssumedContinuing(Arrays.stream(aliceChuanBob).toList(), assertion)); + "Bob", Arrays.stream(aliceChuanBob).toList(), assertion)); assertInstanceOf(NENAssertion.class, assertion); } @@ -197,7 +195,7 @@ void testGuideToRaireExample1() throws RaireServiceException { NEBAssertion nebAssertion = (NEBAssertion) nebMaybeAssertion.get(); assertTrue(correctDBAssertionData(8, 8 / 27.0, 27 / 8.0, - "Chuan", "Bob", nebAssertion)); + "Chuan", "Bob", List.of(), nebAssertion)); } /** @@ -260,7 +258,7 @@ public void simpleContestSingleCounty() throws RaireServiceException { assertTrue(nebMaybeAssertion.isPresent()); NEBAssertion nebAssertion = (NEBAssertion) nebMaybeAssertion.get(); assertTrue(correctDBAssertionData(1, 0.2, 5, "Alice", - "Chuan", nebAssertion)); + "Chuan", List.of(), nebAssertion)); // There should be one NEN assertion: Alice > Bob if only {Alice,Bob} remain. Optional nenMaybeAssertion = assertions.stream() @@ -268,8 +266,7 @@ public void simpleContestSingleCounty() throws RaireServiceException { assertTrue(nenMaybeAssertion.isPresent()); NENAssertion nenAssertion = (NENAssertion) nenMaybeAssertion.get(); assertTrue(correctDBAssertionData(1, 0.2, 5, "Alice", - "Bob", nenAssertion)); - assertTrue(correctAssumedContinuing(List.of("Bob","Alice"), nenAssertion)); + "Bob", List.of("Bob","Alice"), nenAssertion)); } /** @@ -284,7 +281,8 @@ public void simpleContestCrossCounty() throws RaireServiceException { RaireResultOrError response = generateAssertionsService.generateAssertions(request); assertNotNull(response.Ok); assertNull(response.Err); - assertTrue(StringUtils.containsIgnoreCase(request.candidates.get(response.Ok.winner), "Alice")); + assertTrue(StringUtils.containsIgnoreCase(request.candidates.get(response.Ok.winner), + "Alice")); // Test persistence of assertions generated by raire-java. generateAssertionsService.persistAssertions(response.Ok, request); @@ -298,15 +296,15 @@ public void simpleContestCrossCounty() throws RaireServiceException { assertTrue(nebMaybeAssertion.isPresent()); NEBAssertion nebAssertion = (NEBAssertion) nebMaybeAssertion.get(); assertTrue(correctDBAssertionData(1, 0.2, 5, "Alice", - "Chuan", nebAssertion)); + "Chuan", List.of(), nebAssertion)); // There should be one NEN assertion: Alice > Bob if only {Alice,Bob} remain. - Optional nenMaybeAssertion = assertions.stream().filter(a -> a instanceof NENAssertion).findFirst(); - assertTrue(nenMaybeAssertion.isPresent()); + Optional nenMaybeAssertion = assertions.stream().filter( + a -> a instanceof NENAssertion).findFirst(); assertTrue(nenMaybeAssertion.isPresent()); NENAssertion nenAssertion = (NENAssertion) nenMaybeAssertion.get(); assertTrue(correctDBAssertionData(1, 0.2, 5, "Alice", - "Bob", nenAssertion)); - assertTrue(correctAssumedContinuing(List.of("Bob","Alice"), nenAssertion)); + "Bob", List.of("Bob","Alice"), nenAssertion)); + } @@ -329,7 +327,8 @@ public void simpleContestSingleCountyDoubleBallots() throws RaireServiceExceptio RaireResultOrError response = generateAssertionsService.generateAssertions(request); assertNotNull(response.Ok); assertNull(response.Err); - assertTrue(StringUtils.containsIgnoreCase(request.candidates.get(response.Ok.winner), "Alice")); + assertTrue(StringUtils.containsIgnoreCase(request.candidates.get(response.Ok.winner), + "Alice")); // Test persistence of assertions generated by raire-java. generateAssertionsService.persistAssertions(response.Ok, request); @@ -342,7 +341,7 @@ public void simpleContestSingleCountyDoubleBallots() throws RaireServiceExceptio assertTrue(nebMaybeAssertion.isPresent()); NEBAssertion nebAssertion = (NEBAssertion) nebMaybeAssertion.get(); assertTrue(correctDBAssertionData(1, 0.1, 10, "Alice", - "Chuan", nebAssertion)); + "Chuan", List.of(), nebAssertion)); // There should be one NEN assertion: Alice > Bob if only {Alice,Bob} remain. Optional nenMaybeAssertion = assertions.stream() @@ -350,8 +349,7 @@ public void simpleContestSingleCountyDoubleBallots() throws RaireServiceExceptio assertTrue(nenMaybeAssertion.isPresent()); NENAssertion nenAssertion = (NENAssertion) nenMaybeAssertion.get(); assertTrue(correctDBAssertionData(1, 0.1, 10, "Alice", - "Bob", nenAssertion)); - assertTrue(correctAssumedContinuing(List.of("Bob","Alice"), nenAssertion)); + "Bob", List.of("Bob","Alice"), nenAssertion)); } /** @@ -714,7 +712,7 @@ void checkGuideToRaireExample2Assertions(List assertions){ assertTrue(nebMaybeAssertion.isPresent()); NEBAssertion nebAssertion = (NEBAssertion) nebMaybeAssertion.get(); assertTrue(correctDBAssertionData(10, 10 / 41.0, 4.1, - "Chuan","Alice", nebAssertion)); + "Chuan","Alice", List.of(), nebAssertion)); // There should be one NEN assertion: Chuan > Bob if only {Chuan,Bob} remain. // Margin is 9,000, but data is divided by 1000, so 9. Difficulty is 41/9 = 4.5555..., @@ -725,8 +723,7 @@ void checkGuideToRaireExample2Assertions(List assertions){ assertTrue(nenMaybeAssertion.isPresent()); NENAssertion nenAssertion = (NENAssertion) nenMaybeAssertion.get(); assertTrue(correctDBAssertionData(9, 9/41.0, 41.0/9, - "Chuan", "Bob", nenAssertion)); - assertTrue(correctAssumedContinuing(List.of("Chuan","Bob"), nenAssertion)); + "Chuan", "Bob", List.of("Chuan","Bob"), nenAssertion)); } /** diff --git a/src/test/java/au/org/democracydevelopers/raireservice/testUtils.java b/src/test/java/au/org/democracydevelopers/raireservice/testUtils.java index b090904..ad4bd94 100644 --- a/src/test/java/au/org/democracydevelopers/raireservice/testUtils.java +++ b/src/test/java/au/org/democracydevelopers/raireservice/testUtils.java @@ -189,16 +189,19 @@ public static boolean correctAPIAssertionData(String type, int margin, double di * @param winner the expected winner * @param loser the expected loser * @param assertion the assertion to be checked (either as an Assertion or as json) + * @param assumedContinuing the list of candidate names expected to be in the + * 'assumed continuing' field. * @return true if the assertion's data match all the expected values. */ public static boolean correctDBAssertionData(int margin, double dilutedMargin, double difficulty, - String winner, String loser, Assertion assertion) { + String winner, String loser, List assumedContinuing, Assertion assertion) { return margin == assertion.getMargin() && doubleComparator.compare(difficulty, assertion.getDifficulty()) == 0 && doubleComparator.compare(dilutedMargin, assertion.getDilutedMargin()) == 0 && loser.equals(assertion.getLoser()) - && winner.equals(assertion.getWinner()); + && winner.equals(assertion.getWinner()) + && setsNoDupesEqual(assertion.getAssumedContinuing(), assumedContinuing); } /** @@ -231,7 +234,7 @@ public static boolean correctDBAssertionData(long id, int margin, double diluted int otherCount, BigDecimal currentRisk, String contestName, Assertion assertion){ boolean test = correctDBAssertionData(margin, dilutedMargin, difficulty, winner, - loser, assertion); + loser, assumedContinuing, assertion); return test && assertion.getEstimatedSamplesToAudit() == estimatedSamplesToAudit && assertion.getOptimisticSamplesToAudit() == optimisticSamplesToAudit && @@ -241,24 +244,11 @@ public static boolean correctDBAssertionData(long id, int margin, double diluted assertion.getTwoVoteOverCount() == twoVoteOverCount && assertion.getOtherCount() == otherCount && assertion.getCurrentRisk().compareTo(currentRisk) == 0 && - correctAssumedContinuing(assumedContinuing, assertion) && assertion.getCvrDiscrepancy().equals(cvrDiscrepancies) && assertion.getId() == id && assertion.getContestName().equals(contestName); } - - /** - * Utility to check that the expected assumedContinuing list matches the one in the assertion, - * ignoring order. - * @param expectedNames the list of candidate names expected to be in the 'assumed continuing' field. - * @param assertion the assertion to be checked. - * @return true if the NEN assertion's 'assumed continuing' list matches expectedNames, ignoring order. - */ - public static boolean correctAssumedContinuing(List expectedNames, Assertion assertion) { - return setsNoDupesEqual(assertion.getAssumedContinuing(), expectedNames); - } - /** * Check that the max difficulty of a list of assertions matches the expected difficulty. * @param expectedDifficulty the expected difficulty, generated by raire-java and raire-rs directly.