示例#1
0
def test_update_results_multiple_value() -> None:
    """Test update_result for not existed and existed riding"""
    e = Election(date(2000, 2, 8))
    e.update_results('r1', 'ndp', 0)
    res1 = e.results_for('r1', 'ndp')
    assert res1 == 0
    assert 'r1' in e._ridings and 'r1' in e._results
    assert 'ndp' in e._parties and 'ndp' in e._results['r1']
    e.update_results('r2', 'nap', 12)
    res2 = e.results_for('r2', 'nap')
    assert res2 == 12
    assert 'r2' in e._ridings and 'r2' in e._results
    assert 'nap' in e._parties and 'nap' in e._results['r2']
    e.update_results('r2', 'nap', 32)
    res2 = e.results_for('r2', 'nap')
    assert res2 == 44
    assert 'r2' in e._ridings and 'r2' in e._results
    assert 'nap' in e._parties and 'nap' in e._results['r2']
    e.update_results('r1', 'nap', 2)
    res2 = e.results_for('r1', 'nap')
    assert res2 == 2
    assert 'r1' in e._ridings and 'r1' in e._results
    assert 'nap' in e._parties and 'nap' in e._results['r1']
    e.update_results('r1', 'ndp', 2)
    res2 = e.results_for('r1', 'ndp')
    assert res2 == 2
    assert 'r1' in e._ridings and 'r1' in e._results
    assert 'ndp' in e._parties and 'ndp' in e._results['r1']
示例#2
0
def test_update_results_0_votes() -> None:
    """Test update_result for not existed and existed riding"""
    e = Election(date(2000, 2, 8))
    e.update_results('r1', 'ndp', 0)
    res1 = e.results_for('r1', 'ndp')
    assert res1 == 0
    assert 'r1' in e._ridings and 'r1' in e._results
    assert 'ndp' in e._parties and 'ndp' in e._results['r1']
    e.update_results('r1', 'nap', 0)
    res2 = e.results_for('r1', 'nap')
    assert res2 == 0
    assert 'r1' in e._ridings and 'r1' in e._results
    assert 'nap' in e._parties and 'nap' in e._results['r1']
示例#3
0
def test_results_for_party_in_two_ridings() -> None:
    """Test results_for for a party in two ridings"""
    e = Election(date(2000, 2, 8))
    e.update_results('r1', 'ndp', 2)
    e.update_results('r2', 'ndp', 4)
    res1 = e.results_for('r1', 'ndp')
    res2 = e.results_for('r2', 'ndp')
    assert res1 == 2
    assert res2 == 4
示例#4
0
def test_results_for_party_0_votes() -> None:
    """Test results_for for party that has 0 votes"""
    e = Election(date(2000, 2, 8))
    e.update_results('r1', 'ndp', 0)
    res1 = e.results_for('r1', 'ndp')
    assert res1 == 0
示例#5
0
def test_results_for_non_exist_party() -> None:
    """Test results_for for party that has no vote"""
    e = Election(date(2000, 2, 8))
    e.update_results('r1', 'ndp', 2)
    res1 = e.results_for('r1', 'np')
    assert res1 is None
示例#6
0
def test_results_for_non_exist_riding_and_party() -> None:
    """Test results_for for riding and party that has no vote"""
    e = Election(date(2000, 2, 8))
    res1 = e.results_for('r1', 'pc')
    assert res1 is None