def irv_edge(election_dirname, config_dirname=None): """ Generate election 8-irv1 using syn2 then run audit on it with OpenAuditTool. """ with warnings.catch_warnings(record=True): # Generate election from object storing pseudo command-line arguments. e = OpenAuditTool.Election() syn_args = Args() syn_args.election_dirname = election_dirname syn_args.config_dirname = config_dirname syn_args.syn_type = '3' cli_syn.dispatch(e, syn_args) # Audit election e = OpenAuditTool.Election() OpenAuditTool_args = Args() OpenAuditTool_args.election_dirname = election_dirname OpenAuditTool_args.election_name = election_dirname OpenAuditTool_args.elections_root = './elections' OpenAuditTool_args.set_audit_seed = int(time.clock() * 100000) OpenAuditTool_args.read_election_spec = False OpenAuditTool_args.read_reported = False OpenAuditTool_args.make_audit_orders = False OpenAuditTool_args.read_audited = False OpenAuditTool_args.audit = True OpenAuditTool_args.pause = False # added for new planner code: OpenAuditTool_args.num_winners = 1 OpenAuditTool_args.max_num_it = 100 OpenAuditTool_args.sample_by_size = False OpenAuditTool_args.use_discrete_rm = False OpenAuditTool_args.pick_county_func = "round_robin" cli_OpenAuditTool.dispatch(e, OpenAuditTool_args)
def test_4_easy(): """ Generate election 4-easy using syn2 then run audit on it with OpenAuditTool. """ with warnings.catch_warnings(record=True): # Generate election from object storing pseudo command-line arguments. e = OpenAuditTool.Election() syn_args = Args() syn_args.election_dirname = '4-easy' syn_args.syn_type = '2' cli_syn.dispatch(e, syn_args) # Audit election e = OpenAuditTool.Election() OpenAuditTool_args = Args() OpenAuditTool_args.election_dirname = '4-easy' OpenAuditTool_args.election_name = '4-easy' OpenAuditTool_args.elections_root = './elections' OpenAuditTool_args.set_audit_seed = 42 OpenAuditTool_args.read_election_spec = False OpenAuditTool_args.read_reported = False OpenAuditTool_args.make_audit_orders = False OpenAuditTool_args.read_audited = False OpenAuditTool_args.audit = True OpenAuditTool_args.pause = False # added for new planner code: OpenAuditTool_args.num_winners = 2 OpenAuditTool_args.max_num_it = 100 OpenAuditTool_args.sample_by_size = False OpenAuditTool_args.use_discrete_rm = False OpenAuditTool_args.pick_county_func = "round_robin" cli_OpenAuditTool.dispatch(e, OpenAuditTool_args)
def test_4_easy(): """ Generate election 4-easy using syn2 then run audit on it with OpenAuditTool. """ with warnings.catch_warnings(record=True): # Generate election from object storing pseudo command-line arguments. e = OpenAuditTool.Election() syn_args = Args() syn_args.election_dirname = '4-easy' syn_args.syn_type = '2' cli_syn.dispatch(e, syn_args) # Audit election e = OpenAuditTool.Election() OpenAuditTool_args = Args() OpenAuditTool_args.election_dirname = '4-easy' OpenAuditTool_args.election_name = '4-easy' OpenAuditTool_args.elections_root = './elections' OpenAuditTool_args.set_audit_seed = 42 OpenAuditTool_args.read_election_spec = False OpenAuditTool_args.read_reported = False OpenAuditTool_args.make_audit_orders = False OpenAuditTool_args.read_audited = False OpenAuditTool_args.audit = True OpenAuditTool_args.pause = False cli_OpenAuditTool.dispatch(e, OpenAuditTool_args)
def test_expand_contest_groups_defs_2(): e = OpenAuditTool.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_gids_in_list(): e = OpenAuditTool.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(): e = OpenAuditTool.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 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 = OpenAuditTool.Election() args = cli_syn.parse_args() cli_syn.dispatch(e, args)
def test(): e = OpenAuditTool.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)