def test_4_easy(): """ Generate election 4-easy using syn2 then run audit on it with multi. """ with warnings.catch_warnings(record=True): # Generate election from object storing pseudo command-line arguments. e = multi.Election() syn_args = Args() syn_args.election_dirname = '4-easy' syn_args.syn_type = '2' cli_syn.dispatch(e, syn_args) # Audit election e = multi.Election() multi_args = Args() multi_args.election_dirname = '4-easy' multi_args.election_name = '4-easy' multi_args.elections_root = './elections' multi_args.set_audit_seed = 42 multi_args.read_election_spec = False multi_args.read_reported = False multi_args.make_audit_orders = False multi_args.read_audited = False multi_args.audit = True multi_args.pause = False cli_multi.dispatch(e, multi_args)
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]
def test_expand_2(): e = multi.Election() e.gids = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] e.cids = [110, 220, 330, 440, 550, 660, 770, 880, 990, 10100, 11110, 12120] e.cgids_g[1] = [110, 2, 5, 6] e.cgids_g[2] = [220, 3, 11, 12] e.cgids_g[3] = [330, 4, 9, 10] e.cgids_g[4] = [440, 1, 7, 8] e.cgids_g[5] = [550] e.cgids_g[6] = [660] e.cgids_g[7] = [770] e.cgids_g[8] = [880] e.cgids_g[9] = [990] e.cgids_g[10] = [10100] e.cgids_g[11] = [11110] e.cgids_g[12] = [12120] print("Input:") print(" cids:", e.cids) print(" gids:", e.gids) for gid in e.gids: print(" {}->{}".format(gid, e.cgids_g[gid])) expand_contest_group_defs(e) print("Output:") for gid in e.gids: print(" {}->{}".format(gid, e.cids_g[gid]))
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]
def test(): e = multi.Election() test_read_election_spec_general(e) test_read_election_spec_contests(e) test_read_election_spec_contest_groups(e) test_read_election_spec_collections(e)
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]
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]
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]
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]
def test_expand(): e = multi.Election() e.gids = [1, 2, 3, 4, 5, 6, 7] e.cids = [11, 22, 33, 44, 55, 66, 77] e.cgids_g[1] = [11, 2] e.cgids_g[2] = [22, 3, 4] e.cgids_g[3] = [33] e.cgids_g[4] = [44, 5] e.cgids_g[5] = [55, 4] e.cgids_g[6] = [66, 1, 7] e.cgids_g[7] = [77, 3] print("Input:") print(" cids:", e.cids) print(" gids:", e.gids) for gid in e.gids: print(" {}->{}".format(gid, e.cgids_g[gid])) expand_contest_group_defs(e) print("Output:") for gid in e.gids: print(" {}->{}".format(gid, e.cids_g[gid]))
def generate_segments(e, syn, low, high): """ Return list of random segments (r, s) where low <= r < s <= high. Number of segments returned is (high-low). Since r<s, does not return segments of the form (k, k). Intent is that cids are integers in range low <= cid <= high, and each segment yields a contest group covering cids r..s (inclusive). The segments "nest" -- given any two segments, either they are disjoint, or they are equal, or one contains the other. """ assert low <= high L = [] if low != high: L.append((low, high)) mid = syn.RandomState.choice(range(low, high)) L.extend(generate_segments(e, syn, low, mid)) L.extend(generate_segments(e, syn, mid + 1, high)) return L if __name__ == "__main__": e = multi.Election() args = cli_syn.parse_args() cli_syn.dispatch(e, args)