Exemplo n.º 1
0
def test_expand_contest_groups_defs_2():

    e = multi.Election()
    graph_2(e)

    with warnings.catch_warnings(record=True) as w:
        groups.expand_contest_group_defs(e)
        assert len(w) == 4
        assert str(w[0].message) == 'Group id 1 is in a cycle!'
        assert str(w[1].message) == 'Group id 2 is in a cycle!'
        assert str(w[2].message) == 'Group id 3 is in a cycle!'
        assert str(w[3].message) == 'Group id 4 is in a cycle!'

    assert e.cids_g[1] == [
        110, 220, 330, 440, 770, 880, 990, 10100, 11110, 12120, 550, 660
    ]
    assert e.cids_g[2] == [
        220, 330, 440, 110, 550, 660, 770, 880, 990, 10100, 11110, 12120
    ]
    assert e.cids_g[3] == [
        330, 440, 110, 220, 11110, 12120, 550, 660, 770, 880, 990, 10100
    ]
    assert e.cids_g[4] == [
        440, 110, 220, 330, 990, 10100, 11110, 12120, 550, 660, 770, 880
    ]
    assert e.cids_g[5] == [550]
    assert e.cids_g[6] == [660]
    assert e.cids_g[7] == [770]
    assert e.cids_g[8] == [880]
    assert e.cids_g[9] == [990]
    assert e.cids_g[10] == [10100]
    assert e.cids_g[11] == [11110]
    assert e.cids_g[12] == [12120]
Exemplo n.º 2
0
def finish_election_spec_contest_groups(e):

    groups.expand_contest_group_defs(e)

    for pbcid in e.pbcids:
        e.possible_cid_p[pbcid] = {}
        e.required_cid_p[pbcid] = {}
    for cid in e.cids:
        e.possible_pbcid_c[cid] = {}
        e.required_pbcid_c[cid] = {}

    for pbcid in e.pbcids:
        req_gid = e.required_gid_p[pbcid]
        poss_gid = e.possible_gid_p[pbcid]
        for cid in e.cids:
            # "" req_gid means nothing is required.
            if req_gid != "" and cid in e.cids_g[req_gid]:
                utils.nested_set(e.required_cid_p, [pbcid, cid], "True")
                utils.nested_set(e.required_pbcid_c, [cid, pbcid], "True")
            # enforce that possible contests includes all contests
            # "" poss_gid means everything is possible
            if poss_gid == "" or cid in e.cids_g[poss_gid] or cid in e.cids_g[
                    req_gid]:
                utils.nested_set(e.possible_cid_p, [pbcid, cid], "True")
                utils.nested_set(e.possible_pbcid_c, [cid, pbcid], "True")
Exemplo n.º 3
0
def test_expand_contest_groups_defs_2():

    print("test_expand_contest_groups_defs_2")
    e = multi.Election()
    graph_2(e)

    groups.expand_contest_group_defs(e)

    assert e.cids_g[1] == [
        110, 220, 330, 440, 770, 880, 990, 10100, 11110, 12120, 550, 660
    ]
    assert e.cids_g[2] == [
        220, 330, 440, 110, 550, 660, 770, 880, 990, 10100, 11110, 12120
    ]
    assert e.cids_g[3] == [
        330, 440, 110, 220, 11110, 12120, 550, 660, 770, 880, 990, 10100
    ]
    assert e.cids_g[4] == [
        440, 110, 220, 330, 990, 10100, 11110, 12120, 550, 660, 770, 880
    ]
    assert e.cids_g[5] == [550]
    assert e.cids_g[6] == [660]
    assert e.cids_g[7] == [770]
    assert e.cids_g[8] == [880]
    assert e.cids_g[9] == [990]
    assert e.cids_g[10] == [10100]
    assert e.cids_g[11] == [11110]
    assert e.cids_g[12] == [12120]
Exemplo n.º 4
0
def test_expand_gids_in_list():

    print("test_expand_gids_in_list")

    e = multi.Election()
    graph_1(e)

    groups.expand_contest_group_defs(e)

    assert groups.expand_gids_in_list(e, [1, 22, 3, 4, 55, 66]) \
        == [11, 22, 33, 44, 55, 22, 33, 44, 55, 55, 66]
Exemplo n.º 5
0
def test_expand_gids_in_list():

    e = multi.Election()
    graph_1(e)

    with warnings.catch_warnings(record=True) as w:
        groups.expand_contest_group_defs(e)
        assert len(w) == 2
        assert str(w[0].message) == 'Group id 4 is in a cycle!'
        assert str(w[1].message) == 'Group id 5 is in a cycle!'

    assert groups.expand_gids_in_list(e, [1, 22, 3, 4, 55, 66]) \
        == [11, 22, 33, 44, 55, 22, 33, 44, 55, 55, 66]
Exemplo n.º 6
0
def test_expand_contest_group_defs():

    print("test_expand_contest_groups_defs")
    e = multi.Election()
    graph_1(e)

    groups.expand_contest_group_defs(e)

    assert e.cids_g[1] == [11, 22, 33, 44, 55]
    assert e.cids_g[2] == [22, 33, 44, 55]
    assert e.cids_g[3] == [33]
    assert e.cids_g[4] == [44, 55]
    assert e.cids_g[5] == [55, 44]
    assert e.cids_g[6] == [66, 11, 22, 33, 44, 55, 77]
    assert e.cids_g[7] == [77, 33]
Exemplo n.º 7
0
def test_expand_contest_group_defs():

    e = multi.Election()
    graph_1(e)

    with warnings.catch_warnings(record=True) as w:
        groups.expand_contest_group_defs(e)
        assert len(w) == 2
        assert str(w[0].message) == 'Group id 4 is in a cycle!'
        assert str(w[1].message) == 'Group id 5 is in a cycle!'

    assert e.cids_g[1] == [11, 22, 33, 44, 55]
    assert e.cids_g[2] == [22, 33, 44, 55]
    assert e.cids_g[3] == [33]
    assert e.cids_g[4] == [44, 55]
    assert e.cids_g[5] == [55, 44]
    assert e.cids_g[6] == [66, 11, 22, 33, 44, 55, 77]
    assert e.cids_g[7] == [77, 33]