Skip to content

Commit

Permalink
Correct GetAssertions tests; remove winner from Metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
vteague committed Jun 9, 2024
1 parent 52a3f85 commit aa7e90d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public RaireSolution getRaireSolution(GetAssertionsRequest request)
metadata.put(Metadata.RISK_LIMIT, request.riskLimit);
metadata.put(Metadata.CONTEST, request.contestName);
metadata.put(Metadata.TOTAL_BALLOTS, request.totalAuditableBallots);
metadata.put(Metadata.WINNER, request.winner);

// Translate the assertions extracted from the database into AssertionAndDifficulty objects,
// keeping track of the maximum difficulty and minimum margin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ public class Metadata {
*/
public final static String CONTEST = "contest";

/**
* Metadata field name for the contest's winner.
*/
public final static String WINNER = "winner";

/**
* Metadata field name for the contest's total Auditable ballots.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testValidRequestWithNoAssertionsJSON() {
String url = "http://localhost:" + port + getAssertionsJSONEndpoint;

String requestAsJson = "{\"riskLimit\":0.05,\"contestName\":\"Ballina Mayoral\","
+ defaultCountJson + "," + defaultWinnerJSON + "," + "\"candidates\":[\"Alice\",\"Bob\"]}";
+ defaultCountJson + "," + defaultWinnerJSON + "," + "\"candidates\":[\"Bob\",\"Chuan\"]}";

HttpEntity<String> request = new HttpEntity<>(requestAsJson, httpHeaders);
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
Expand Down Expand Up @@ -227,7 +227,12 @@ private static Stream<Arguments> expectedBadRequestErrors() {
Arguments.of("JSON", riskLimit, ballinaMayoral, "-10",
"\""+defaultWinner+"\"", aliceAndBobJSON, "Non-positive total auditable ballots"),
Arguments.of("CSV", riskLimit, ballinaMayoral, "-10",
"\""+defaultWinner+"\"", aliceAndBobJSON, "Non-positive total auditable ballots")
"\""+defaultWinner+"\"", aliceAndBobJSON, "Non-positive total auditable ballots"),
// A request with a winner who is not one of the candidates is invalid.
Arguments.of("JSON", riskLimit, ballinaMayoral, ""+defaultCount,
"\""+defaultWinner+"\"", aliceAndBobJSON, "not one of the candidates"),
Arguments.of("CSV", riskLimit, ballinaMayoral, ""+defaultCount,
"\""+defaultWinner+"\"", aliceAndBobJSON, "not one of the candidates")
);
}

Expand All @@ -241,7 +246,7 @@ public void testValidRequestWithNoAssertionsCSV() {
String url = "http://localhost:" + port + getAssertionsCSVEndpoint;

String requestAsJson = "{\"riskLimit\":0.05,\"contestName\":\"Ballina Mayoral\","
+ defaultCountJson + "," + defaultWinnerJSON + "," + "\"candidates\":[\"Alice\",\"Bob\"]}";
+ defaultCountJson + "," + defaultWinnerJSON + "," + "\"candidates\":[\"Bob\",\"Chuan\"]}";

HttpEntity<String> request = new HttpEntity<>(requestAsJson, httpHeaders);
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ the raire assertion generation engine (https://github.com/DemocracyDevelopers/ra
* GetAssertionsInProgressServiceTestsJsonAndCsv.java.
* Contests which will be used for validity testing are preloaded into the database using
* src/test/resources/data.sql.
* FIXME add winner, risk limit, total auditable ballots.
*/
@ActiveProfiles("assertions-in-progress")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Expand Down Expand Up @@ -103,7 +104,7 @@ void retrieveAssertionsExistentContestOneNEBAssertionJSON() {
String url = baseURL + port + getAssertionsJsonEndpoint;

GetAssertionsRequest request = new GetAssertionsRequest(oneNEBAssertionContest, defaultCount,
List.of("Alice","Bob"), defaultWinner, BigDecimal.valueOf(0.1));
List.of("Alice","Bob"), "Bob", BigDecimal.valueOf(0.1));

ResponseEntity<RaireSolution> response = restTemplate.postForEntity(url, request,
RaireSolution.class);
Expand Down Expand Up @@ -136,7 +137,7 @@ void retrieveAssertionsExistentContestOneNEBAssertionCSV() {
String url = baseURL + port + getAssertionsCsvEndpoint;

String requestAsJson = "{\"riskLimit\":0.10,\"contestName\":\"" + oneNEBAssertionContest+"\","
+ defaultCountJson + "," + defaultWinnerJSON + "," + "\"candidates\":[\"Alice\",\"Bob\"]}";
+ defaultCountJson + "," + "\"winner\":\"Bob\""+ "," + "\"candidates\":[\"Alice\",\"Bob\"]}";

HttpEntity<String> request = new HttpEntity<>(requestAsJson, httpHeaders);
String csv = restTemplate.postForEntity(url, request, String.class).getBody();
Expand Down Expand Up @@ -169,7 +170,7 @@ void retrieveAssertionsExistentContestOneNENAssertionJSON() {
String url = baseURL + port + getAssertionsJsonEndpoint;

GetAssertionsRequest request = new GetAssertionsRequest(oneNENAssertionContest, defaultCount,
List.of("Alice","Bob","Charlie","Diego"), defaultWinner, BigDecimal.valueOf(0.1));
List.of("Alice","Bob","Charlie","Diego"), "Diego", BigDecimal.valueOf(0.1));
ResponseEntity<RaireSolution> response = restTemplate.postForEntity(url, request,
RaireSolution.class);

Expand Down Expand Up @@ -202,7 +203,7 @@ void retrieveAssertionsExistentContestOneNENAssertionCSV() {

String requestAsJson =
"{\"riskLimit\":0.10,\"contestName\":\"" + oneNENAssertionContest + "\","
+ defaultCountJson + "," + defaultWinnerJSON + ","
+ defaultCountJson + "," +"\"winner\":\"Alice\"" + ","
+ "\"candidates\":[\"Alice\",\"Bob\",\"Charlie\",\"Diego\"]}";

HttpEntity<String> request = new HttpEntity<>(requestAsJson, httpHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class GetAssertionsRequestTests {
public void validRequestForIRVContestIsValid() {
testUtils.log(logger, "validRequestForIRVContestIsValid");
GetAssertionsRequest validRequest = new GetAssertionsRequest("Ballina Mayoral",
defaultCount, List.of("Alice"), defaultWinner, BigDecimal.valueOf(0.03));
defaultCount, List.of("Alice"), "Alice", BigDecimal.valueOf(0.03));
assertDoesNotThrow(() -> validRequest.Validate(contestRepository));
}

Expand Down Expand Up @@ -144,7 +144,10 @@ private static Stream<Arguments> expectedExceptionMessages() {
// A request with a negative totalAuditableBallots is invalid.
// (Note that a request with zero auditable ballots is strange but valid.)
Arguments.of(ballinaMayoral, -10, alice, defaultWinner,
defaultRiskLimit, "Non-positive total auditable ballots")
defaultRiskLimit, "Non-positive total auditable ballots"),
// A request with a winner who is not one of the candidates is invalid.
Arguments.of(ballinaMayoral, defaultCount, alice, "Bob",
defaultRiskLimit, "not one of the candidates")
);
}
}

0 comments on commit aa7e90d

Please sign in to comment.