Пример #1
0
def test_athena_minerva_paper():
    contest = Contest(100000, {
        'A': 75000,
        'B': 25000
    }, 1, ['A'], ContestType.MAJORITY)
    athena = Athena(.1, 1, .1, contest)
    minerva = Minerva(.1, .1, contest)
    athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [50])
    minerva.compute_min_winner_ballots(minerva.sub_audits['A-B'], [50])

    # From Athena paper
    assert athena.sub_audits['A-B'].min_winner_ballots == [32]
    assert minerva.sub_audits['A-B'].min_winner_ballots == [31]
Пример #2
0
def test_exceptions():
    contest = Contest(100000, {
        'A': 60000,
        'B': 40000
    }, 1, ['A'], ContestType.MAJORITY)
    with pytest.raises(ValueError):
        Athena(.1, 0, .1, contest)
    athena = Athena(.1, 1, .1, contest)
    with pytest.raises(Exception):
        athena.stopping_condition_pairwise('A-B')
    athena.rounds.append(10)
    with pytest.raises(ValueError):
        athena.stopping_condition_pairwise('X')
    athena.rounds = []
    with pytest.raises(ValueError):
        athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [])
    with pytest.raises(ValueError):
        athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [0])
    with pytest.raises(ValueError):
        athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [1, 2])
    with pytest.raises(ValueError):
        athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [20, 20])
    with pytest.raises(ValueError):
        athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [20, 19])
    with pytest.raises(ValueError):
        athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [10001])

    athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [20])
    with pytest.raises(ValueError):
        athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [20])
    with pytest.raises(ValueError):
        athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [19])
    with pytest.raises(ValueError):
        athena.compute_min_winner_ballots(athena.sub_audits['A-B'], [10001])

    contest2 = Contest(100, {'A': 60, 'B': 30}, 1, ['A'], ContestType.MAJORITY)
    athena2 = Athena(0.1, 1, 1.0, contest2)
    with pytest.raises(ValueError):
        athena2.compute_min_winner_ballots(athena2.sub_audits['A-B'], [91])
    athena2.rounds.append(10)
    with pytest.raises(Exception):
        athena2.compute_all_min_winner_ballots(athena2.sub_audits['A-B'])
    athena2.rounds = []
    with pytest.raises(ValueError):
        athena2.compute_all_min_winner_ballots(athena2.sub_audits['A-B'], 0)
    with pytest.raises(ValueError):
        athena2.compute_all_min_winner_ballots(athena2.sub_audits['A-B'], 200)
    with pytest.raises(ValueError):
        athena2.compute_all_min_winner_ballots(athena2.sub_audits['A-B'], 0)