예제 #1
0
def test_riding_changes_4_election_recuring_ridings() -> None:
    """Test riding_changes with 3 elections of same ridings"""
    j = Jurisdiction('Canada')
    e1 = Election(date(2000, 2, 8))
    e1.update_results('r1', 'ndp', 1)
    e1.update_results('r5', 'lib', 1)
    e1.update_results('r6', 'pc', 1)
    e1.update_results('r2', 'pc', 1)
    e1.update_results('r2', 'lib', 1)
    e1.update_results('r2', 'green', 1)
    e1.update_results('r2', 'ndp', 1)
    e2 = Election(date(2004, 5, 16))
    e2.update_results('r3', 'ndp', 1)
    e2.update_results('r4', 'pc', 1)
    e3 = Election(date(2005, 5, 16))
    e3.update_results('r1', 'ndp', 1)
    e3.update_results('r2', 'pc', 1)
    e4 = Election(date(2006, 5, 16))
    e4.update_results('r3', 'ndp', 1)
    e4.update_results('r2', 'pc', 1)
    e4.update_results('r1', 'pc', 1)
    e4.update_results('r4', 'pc', 1)
    e4.update_results('r5', 'pc', 1)
    j._history[date(2006, 5, 16)] = e4
    j._history[date(2005, 5, 16)] = e3
    j._history[date(2004, 5, 16)] = e2
    j._history[date(2000, 2, 8)] = e1
    res1 = j.riding_changes()
    assert res1 == [({'r1', 'r2', 'r5', 'r6'}, {'r3', 'r4'}),
                    ({'r3', 'r4'}, {'r1', 'r2'}), (set(), {'r3', 'r4', 'r5'})]
예제 #2
0
def test_riding_changes_1_election() -> None:
    """Test riding_changes with 1 election"""
    j = Jurisdiction('Canada')
    e1 = Election(date(2000, 2, 8))
    e1.update_results('r1', 'ndp', 1)
    e1.update_results('r1', 'lib', 1)
    e1.update_results('r1', 'pc', 1)
    e1.update_results('r2', 'pc', 1)
    e1.update_results('r2', 'lib', 1)
    e1.update_results('r2', 'green', 1)
    e1.update_results('r2', 'ndp', 1)
    j._history[date(2000, 2, 8)] = e1
    res1 = j.riding_changes()
    assert res1 == []
예제 #3
0
def test_riding_changes_3_election_different_ridings() -> None:
    """Test riding_changes with 3 elections of totally different ridings"""
    j = Jurisdiction('Canada')
    e1 = Election(date(2000, 2, 8))
    e1.update_results('r1', 'ndp', 1)
    e1.update_results('r2', 'ndp', 1)
    e2 = Election(date(2004, 5, 16))
    e2.update_results('r3', 'ndp', 1)
    e2.update_results('r4', 'pc', 1)
    e3 = Election(date(2005, 5, 16))
    e3.update_results('r5', 'ndp', 1)
    e3.update_results('r6', 'pc', 1)
    j._history[date(2005, 5, 16)] = e3
    j._history[date(2004, 5, 16)] = e2
    j._history[date(2000, 2, 8)] = e1
    res1 = j.riding_changes()
    assert res1 == [({'r1', 'r2'}, {'r3', 'r4'}), ({'r3', 'r4'}, {'r5', 'r6'})]
예제 #4
0
def test_riding_changes_2_election_same_ridings() -> None:
    """Test riding_changes with 2 elections of same ridings"""
    j = Jurisdiction('Canada')
    e1 = Election(date(2000, 2, 8))
    e1.update_results('r1', 'ndp', 1)
    e1.update_results('r1', 'lib', 1)
    e1.update_results('r1', 'pc', 1)
    e1.update_results('r2', 'pc', 1)
    e1.update_results('r2', 'lib', 1)
    e1.update_results('r2', 'green', 1)
    e1.update_results('r2', 'ndp', 1)
    e2 = Election(date(2004, 5, 16))
    e2.update_results('r1', 'ndp', 1)
    e2.update_results('r2', 'pc', 1)
    j._history[date(2004, 5, 16)] = e2
    j._history[date(2000, 2, 8)] = e1
    res1 = j.riding_changes()
    assert res1 == [(set(), set())]