def run_test(precincts_file):
    precincts, seed = util.load_precincts(precincts_file)
    results_file = precincts_file.replace(".json", ".csv")
    voters = simulate_election_day(precincts, seed)

    with open(results_file) as f:
        reader = csv.DictReader(f)

        results = {}
        for row in reader:
            results.setdefault(row["precinct"], []).append(row)

        for p in precincts:
            pname = p["name"]

            pvoters = voters[pname]
            rvoters = results.get(pname, [])

            assert len(pvoters) == len(
                rvoters
            ), "Incorrect number of voters for precinct '{}' (got {}, expected {}".format(
                pname, len(pvoters), len(rvoters))

            i = 0
            for returned_voter, expected_voter in zip(pvoters, rvoters):
                fcompare(pname, i, "arrival time", returned_voter.arrival_time,
                         float(expected_voter["arrival_time"]))
                fcompare(pname, i, "voting duration",
                         returned_voter.voting_duration,
                         float(expected_voter["voting_duration"]))
                fcompare(pname, i, "start time", returned_voter.start_time,
                         float(expected_voter["start_time"]))
                i += 1
def rt_helper(prefix, num_booths, expected):
    params_filename = prefix + ".json"
    params = simulate.setup_params(params_filename, num_booths)
    expected = [eval(row[0]) for row in csv.reader(open(prefix + "-exact-expected-" + str(num_booths) + ".txt"))]

    error_str = "Results of trial {} do not match.  Expected: {}     Got: {}"
    for t in range(params["num_trials"]):
        actual = simulate.simulate_election_day(params)
        print((t, expected[t], actual))
        if expected[t] != actual:
            pytest.fail(error_str.format(t, expected[t], actual))
def sed_helper(params_filename, num_booths, expected):
    params = simulate.setup_params(params_filename, num_booths)
    actual = simulate.simulate_election_day(params)
    if (actual != expected):
        pytest.fail("Expected:{}  Got: {}". format(actual, expected))
Exemple #4
0

import simulate
#import priority_queue

#params = simulate.setup_params('data/params2.json', 8)
#Expects True

#params = simulate.setup_params('data/params2.json', 6)
#Expects False

#params = simulate.setup_params('data/params0.json', 1)
#Expects False

params = simulate.setup_params('data/params0.json', 2)
#Expects False

s = simulate.simulate_election_day(params)
print(s)
def sed_helper(params_filename, num_booths, expected):
    params = simulate.setup_params(params_filename, num_booths)
    actual = simulate.simulate_election_day(params)
    assert actual == expected