Skip to content

Commit

Permalink
Corrected tests; moved num_candidates into raire solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
vteague committed Jun 9, 2024
1 parent aa7e90d commit 7d06969
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,21 @@ public static boolean correctMetadata(List<String> 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;
}

Expand Down

0 comments on commit 7d06969

Please sign in to comment.