Skip to content

Commit

Permalink
Reintroducing changes to Demo.java and Workflow.java that were made a…
Browse files Browse the repository at this point in the history
…s part of PR #231. These changes had been clobbered by a later PR (#232). This should have been caught in review but was not.
  • Loading branch information
michelleblom committed Jan 10, 2025
1 parent 76cf74f commit d01cbb4
Show file tree
Hide file tree
Showing 3 changed files with 392 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class TestClassWithDatabase {
/**
* Container for the mock-up database.
*/
static PostgreSQLContainer<?> postgres = createTestContainer();
protected static PostgreSQLContainer<?> postgres = createTestContainer();


@BeforeClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.log4j.Logger;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import us.freeandfair.corla.persistence.Persistence;

import static org.testng.Assert.*;
import static us.freeandfair.corla.asm.ASMState.DoSDashboardState.*;
Expand Down Expand Up @@ -80,7 +79,7 @@ public void runDemo1() throws InterruptedException {
CVRS.add(dataPath + "Demo1/4-archuleta-kempsey-plusByron-4.csv");
CVRS.add(dataPath + "split-Byron/Byron-5.csv");
CVRS.add(dataPath + "split-Byron/Byron-6.csv");
CVRS.add(dataPath + "Demo1/7-boulder-2023-plusByron-7.csv");
CVRS.add(dataPath + "Demo1/7-unredacted-boulder-2023-plusByron-7.csv");

List<String> MANIFESTS = new ArrayList<>();

Expand All @@ -90,7 +89,7 @@ public void runDemo1() throws InterruptedException {
MANIFESTS.add(dataPath + "NewSouthWales21/Kempsey_Mayoral.manifest.csv");
MANIFESTS.add(dataPath + "split-Byron/Byron-5-manifest.csv");
MANIFESTS.add(dataPath + "split-Byron/Byron-6-manifest.csv");
MANIFESTS.add(dataPath + "Boulder23/Boulder-IRV-Manifest.csv");
MANIFESTS.add(dataPath + "Demo1/7-unredacted-Boulder-IRV-Manifest.csv");

for(int i = 8 ; i <= numCounties ; ++i){
CVRS.add(dataPath + "split-Byron/Byron-" + i + ".csv");
Expand Down Expand Up @@ -132,18 +131,18 @@ public void runDemo1() throws InterruptedException {
assertEquals(dashboard.get(ASM_STATE), PARTIAL_AUDIT_INFO_SET.toString());

// 4. Generate assertions; sanity check
// Pre-load test assertions into the database. Eventually (or in a real run) these will be
// generated by calling the raire-service.
runSQLSetupScript("SQL/demo1-assertions.sql");
generateAssertions("SQL/demo1-assertions.sql", 1);
dashboard = getDoSDashBoardRefreshResponse();

// There should be 4 IRV contests.
assertEquals(4, dashboard.getList("generate_assertions_summaries").size());

// 5. Choose targeted contests for audit.
targetContests(Map.of("City of Longmont - Mayor","COUNTY_WIDE_CONTEST",
final Map<String,String> targets = Map.of("City of Longmont - Mayor","COUNTY_WIDE_CONTEST",
"Byron Mayoral", "STATE_WIDE_CONTEST",
"Kempsey Mayoral", "COUNTY_WIDE_CONTEST"));
"Kempsey Mayoral", "COUNTY_WIDE_CONTEST");
final List<String> irvContests = List.of("Byron Mayoral", "Kempsey Mayoral");
targetContests(targets);

// 6. Set the seed.
setSeed(defaultSeed);
Expand All @@ -157,9 +156,49 @@ public void runDemo1() throws InterruptedException {
Map<String, EstimateSampleSizes.EstimateData> sampleSizes = getSampleSizeEstimates();
assertFalse(sampleSizes.isEmpty());

// TODO Sanity check of assertions and sample size estimates.
// Byron should be 3820. Kempsey 332.
// For each targeted contest, check that the set of assertions: (i) is not empty; (ii) has
// the correct minimum diluted margin; and (ii) has resulted in the correct sample size estimate.
Map<String,Double> expectedDilutedMargins = Map.of("City of Longmont - Mayor", 0.09078192,
"Byron Mayoral", 0.00684644, "Kempsey Mayoral", 0.02200739);

LOGGER.debug("Successfully completed Demo1.");
for(final String c : targets.keySet()) {
verifySampleSize(c, expectedDilutedMargins.get(c),
sampleSizes.get(c).estimatedSamples(), riskLimit, irvContests.contains(c));
}

// 8. Start Audit Round
startAuditRound();

// 9. Log in as each county, and audit all ballots in sample.
List<TestAuditSession> sessions = new ArrayList<>();
for(final int cty : allCounties){
sessions.add(countyAuditInitialise(cty));
}

// ACVR uploads for each county. Cannot run in parallel as corla does not like
// simultaneous database accesses.
for(final TestAuditSession entry : sessions){
auditCounty(1, entry);
}

// Audit board sign off for each county.
for(final TestAuditSession entry : sessions){
countySignOffLogout(entry);
}

// Check that there are no more ballots to sample across all counties in first round,
// and as this demo involved no discrepancies, that all audits are complete.
dashboard = getDoSDashBoardRefreshResponse();
final Map<String,Map<String,Object>> status = dashboard.get(COUNTY_STATUS);

for(final Map.Entry<String,Map<String,Object>> entry : status.entrySet()){
assertEquals(entry.getValue().get(BALLOTS_REMAINING).toString(), "0");
assertEquals(entry.getValue().get(ESTIMATED_BALLOTS).toString(), "0");
assertEquals(entry.getValue().get(DISCREPANCY_COUNT).toString(), "{}");
}

LOGGER.info("Successfully completed Demo1 (First round audit; No Discrepancies).");
}

}
Loading

0 comments on commit d01cbb4

Please sign in to comment.