def test_no_double_te():
    args = Namespace(**args_dict)
    args.locked = ['Rob Gronkowski']
    roster = run(NFL, args)
    qb = roster.sorted_players()[0]
    ntools.assert_equal(qb.pos, 'QB')
    te_count = len([x for x in roster.sorted_players() if x.pos == 'TE'])
    ntools.assert_equals(te_count, 2)
    args.no_double_te = 'y'
    roster = run(NFL, args)
    qb = roster.sorted_players()[0]
    ntools.assert_equal(qb.pos, 'QB')
    te_count = len([x for x in roster.sorted_players() if x.pos == 'TE'])
    ntools.assert_equals(te_count, 1)
Beispiel #2
0
def test_force_combo():
    args = Namespace(**args_dict)
    roster = run(NFL, args)
    qb = roster.sorted_players()[0]
    ntools.assert_equal(qb.pos, 'QB')
    team_count = len([x for x in roster.sorted_players() if x.team == qb.team])
    ntools.assert_equals(team_count, 1)

    args = Namespace(**args_dict)
    args.force_combo = True
    roster = run(NFL, args)
    qb = roster.sorted_players()[0]
    ntools.assert_equal(qb.pos, 'QB')
    team_count = len([x for x in roster.sorted_players() if x.team == qb.team])
    ntools.assert_equals(team_count, 2)
Beispiel #3
0
def test_teams_constraint():
    default_args.teams = ['NE', 'Dal']
    roster = run(POSITIONS[NFL], NFL, [], default_args, True)
    for p in roster.players:
        if p.pos == 'DST':
            continue
        assert p.team == 'NE' or p.team == 'Dal'
Beispiel #4
0
def test_locked_constraint():
    jb = 'Jacoby Brissett'
    default_args.teams = ['NE', 'Dal']
    default_args.banned = []
    default_args.locked = [jb]
    roster = run(POSITIONS[NFL], NFL, [], default_args, True)
    assert [p for p in roster.players if p.name == jb][0].lock
Beispiel #5
0
def test_within_avg():
    avg_test_val = 3
    default_args.v_avg = avg_test_val
    roster = run(POSITIONS[NFL], NFL, [], default_args)
    for player in roster.players:
        assert abs(player.v_avg) < avg_test_val
    default_args.v_avg = 10000
def test_banned_constraint():
    args = Namespace(**args_dict)
    jg = 'Jimmy Garoppolo'
    args.teams = ['NE', 'Dal']
    args.banned = [jg]
    roster = run(NFL, [], args)
    ntools.assert_not_in(jg, [p.name for p in roster.players])
def test_within_avg():
    args = Namespace(**args_dict)
    avg_test_val = 3
    args.v_avg = avg_test_val
    roster = run(NFL, [], args)
    for player in roster.players:
        ntools.assert_less(abs(player.v_avg), avg_test_val)
Beispiel #8
0
def test_teams_constraint():
    default_args.teams = ['NE', 'Dal']
    roster = run(POSITIONS[NFL], NFL, [], default_args)
    for p in roster.players:
        if p.pos == 'DST':
            continue
        assert p.team == 'NE' or p.team == 'Dal'
def test_multi_position():
    args = Namespace(**args_dict)
    args.locked = ['Eli Manning']
    roster = run(NFL, args)
    multi_pos = [p for p in roster.players if p.name == 'Eli Manning']
    ntools.assert_equal(len(multi_pos), 1)
    ntools.assert_equal(multi_pos[0].pos, 'TE')
def test_banned_constraint():
    args = Namespace(**args_dict)
    jg = 'Jimmy Garoppolo'
    args.teams = ['NE', 'Dal']
    args.banned = [jg]
    roster = run(NFL, args)
    ntools.assert_not_in(jg, [p.name for p in roster.players])
Beispiel #11
0
def test_locked_constraint():
    jb = 'Jacoby Brissett'
    default_args.teams = ['NE', 'Dal']
    default_args.banned = []
    default_args.locked = [jb]
    roster = run(POSITIONS[NFL], NFL, [], default_args)
    assert [p for p in roster.players if p.name == jb][0].lock
def test_within_avg():
    args = Namespace(**args_dict)
    avg_test_val = 3
    args.v_avg = avg_test_val
    roster = run(NFL, args)
    for player in roster.players:
        ntools.assert_less(abs(player.v_avg), avg_test_val)
def test_multi_position():
    args = Namespace(**args_dict)
    args.locked = ['Eli Manning']
    roster = run(NFL, [], args)
    multi_pos = [p for p in roster.players if p.name == 'Eli Manning']
    ntools.assert_equal(len(multi_pos), 1)
    ntools.assert_equal(multi_pos[0].pos, 'TE')
def test_teams_constraint():
    args = Namespace(**args_dict)
    args.teams = ['NE', 'Dal']
    roster = run(NFL, args)
    for p in roster.players:
        if p.pos == 'DST':
            continue
        ntools.assert_true(p.team == 'NE' or p.team == 'Dal')
def test_stack():
    args = Namespace(**args_dict)
    args.stack = 'NE'
    args.stack_count = 5
    roster = run(NFL, args)
    ne_players_count = len(
        [p for p in roster.sorted_players() if p.team == 'NE'])
    ntools.assert_equals(5, ne_players_count)
def test_locked_constraint():
    args = Namespace(**args_dict)
    jb = 'Jacoby Brissett'
    args.teams = ['NE', 'Dal']
    args.banned = []
    args.locked = [jb]
    roster = run(NFL, [], args)
    ntools.assert_true([p for p in roster.players if p.name == jb][0].lock)
def test_lock_overrides():
    args = Namespace(**args_dict)
    args.teams = ['NE', 'Dal']
    args.v_avg = 1
    args.locked = ['Eli Manning']
    roster = run(NFL, [], args)
    ntools.assert_true([p for p in roster.players
                        if p.name == 'Eli Manning'][0].lock)
def test_locked_constraint():
    args = Namespace(**args_dict)
    jb = 'Jacoby Brissett'
    args.teams = ['NE', 'Dal']
    args.banned = []
    args.locked = [jb]
    roster = run(NFL, args)
    ntools.assert_true([p for p in roster.players if p.name == jb][0].lock)
def test_teams_constraint():
    args = Namespace(**args_dict)
    args.teams = ['NE', 'Dal']
    roster = run(NFL, [], args)
    for p in roster.players:
        if p.pos == 'DST':
            continue
        ntools.assert_true(p.team == 'NE' or p.team == 'Dal')
def test_lock_overrides():
    args = Namespace(**args_dict)
    args.teams = ['NE', 'Dal']
    args.v_avg = 1
    args.locked = ['Eli Manning']
    roster = run(NFL, args)
    ntools.assert_true(
        [
            p for p in roster.players
            if p.name == 'Eli Manning'
        ][0].lock
    )
def test_te_combo():
    # wr combo
    args = Namespace(**args_dict)
    args.force_combo = True
    args.banned = ['Eli Manning']

    roster = run(NFL, args)
    qb = roster.sorted_players()[0]
    ntools.assert_equal(qb.pos, 'QB')
    team_count = len([x for x in roster.sorted_players() if x.team == qb.team])
    ntools.assert_equals(team_count, 2)

    # qb/te combo
    args.combo_allow_te = True
    roster = run(NFL, args)
    qb = roster.sorted_players()[0]
    ntools.assert_equal(qb.pos, 'QB')
    team_count = len([
        x for x in roster.sorted_players()
        if x.team == qb.team and x.pos == 'TE'
    ])
    ntools.assert_equals(team_count, 1)
Beispiel #22
0
def test_optimize_with_general():
    run_args = Namespace(
        game='draftkings',
        dtype='wr',
        duo='n',
        i=1,
        season=2016,
        w=1,
        historical='n',
        league='NBA',
        limit='n',
        lp=0,
        no_double_te='n',
        mp=100,
        ms=10000,
        s='n',
        sp=3000,
        home=None,
        locked=None,
        teams=None,
        banned=None,
        po=0,
        po_location=None,
        v_avg=10000,
        source='nba_rotogrinders',
        salary_file=os.getcwd() + '/test/data/nba-test-salaries.csv',
        projection_file=os.getcwd() + '/test/data/nba-test-projections.csv',
        flex_position=None,
        min_avg=-1,
        historical_date=None,
    )
    roster = run('NBA', run_args)

    def get_player_count_at_pos(pos):
        return len([
            p for p in roster.players
            if p.nba_general_position == pos
        ])

    ntools.assert_equal(4, get_player_count_at_pos('G'))
    ntools.assert_equal(3, get_player_count_at_pos('F'))
    ntools.assert_equal(1, get_player_count_at_pos('C'))
def test_bad_constraints():
    args = Namespace(**args_dict)
    args.lp = 1000
    roster = run(NFL, [], args)
    ntools.assert_equal(roster, None)
def test_default_constraints():
    args = Namespace(**args_dict)
    roster = run(NFL, args)
    assert roster
def test_is_home():
    args = Namespace(**args_dict)
    args.home = True
    roster = run(NFL, args)
    for p in roster.players:
        ntools.assert_true(p.is_home)
Beispiel #26
0
def test_duo_constraint():
    default_args.duo = 'NE'
    roster = run(POSITIONS[NFL], NFL, [], default_args, True)
    team_instances = Counter([p.team for p in roster.players]).values()
    assert 2 in team_instances
Beispiel #27
0
def test_is_home():
    default_args.home = True
    roster = run(POSITIONS[NFL], NFL, [], default_args)
    for p in roster.players:
        assert p.is_home
    default_args.home = False
def test_is_home():
    args = Namespace(**args_dict)
    args.home = True
    roster = run(NFL, [], args)
    for p in roster.players:
        ntools.assert_true(p.is_home)
Beispiel #29
0
def test_bad_constraints():
    default_args.lp = 1000
    roster = run(POSITIONS[NFL], NFL, [], default_args)
    assert roster is None
Beispiel #30
0
def test_banned_constraint():
    jg = 'Jimmy Garoppolo'
    default_args.teams = ['NE', 'Dal']
    default_args.banned = [jg]
    roster = run(POSITIONS[NFL], NFL, [], default_args, True)
    assert jg not in [p.name for p in roster.players]
def test_min_salary():
    args = Namespace(**args_dict)
    args.sp = 3500
    roster = run(NFL, args)
    for p in roster.players:
        ntools.assert_true(p.cost >= 3500)
def test_bad_constraints():
    args = Namespace(**args_dict)
    args.lp = 1000
    roster = run(NFL, args)
    ntools.assert_equal(roster, None)
def test_duo_constraint():
    args = Namespace(**args_dict)
    args.duo = 'NE'
    roster = run(NFL, [], args)
    team_instances = Counter([p.team for p in roster.players]).values()
    ntools.assert_in(2, team_instances)
Beispiel #34
0
def test_default_constraints():
    roster = run(POSITIONS[NFL], NFL, [], default_args, True)
    assert roster
def test_default_constraints():
    args = Namespace(**args_dict)
    roster = run(NFL, [], args)
    assert roster
def test_multi_roster():
    args = Namespace(**args_dict)
    roster = run(NFL, args)
    second_roster = run(NFL, args, [roster])
    ntools.assert_not_equals(roster == second_roster, True)
def test_multi_roster():
    args = Namespace(**args_dict)
    roster = run(NFL, args)
    second_roster = run(NFL, args, [roster])
    ntools.assert_not_equals(roster == second_roster, True)
def test_duo_constraint():
    args = Namespace(**args_dict)
    args.duo = 'NE'
    roster = run(NFL, args)
    team_instances = Counter([p.team for p in roster.players]).values()
    ntools.assert_in(2, team_instances)
Beispiel #39
0
def test_duo_constraint():
    default_args.duo = 'NE'
    roster = run(POSITIONS[NFL], NFL, [], default_args)
    team_instances = Counter([p.team for p in roster.players]).values()
    assert 2 in team_instances
Beispiel #40
0
def test_default_constraints():
    roster = run(POSITIONS[NFL], NFL, [], default_args)
    assert roster
def test_min_salary():
    args = Namespace(**args_dict)
    args.sp = 3500
    roster = run(NFL, [], args)
    for p in roster.players:
        ntools.assert_true(p.cost >= 3500)
Beispiel #42
0
def test_banned_constraint():
    jg = 'Jimmy Garoppolo'
    default_args.teams = ['NE', 'Dal']
    default_args.banned = [jg]
    roster = run(POSITIONS[NFL], NFL, [], default_args)
    assert jg not in [p.name for p in roster.players]
Beispiel #43
0
argParser.add_argument("--dot", action = "store_true", help = "Generate a dot graph of the program")
args = argParser.parse_args()

# ------------------- #
# Compilation Process #
# ------------------- #

if args.path is '-':
	file = sys.stdin
else: 
	file = open(args.path, 'r')
	fileName, fileExtension = os.path.splitext(args.path)

frontend.read(file.read())

try:
	graph = frontend.get()
except frontend.Error:
	print >> sys.stderr, "There are errors in your program."
	sys.exit(1)

if args.dot: IGR.dot(graph, path = "pre.dot")
optimize.run(graph)
if args.dot: IGR.dot(graph, path = "post.dot")

dis = backend.convert(graph)
if args.path is '-': 
	print dis
else:
	file = open('%s.%s' % (fileName, 'dis'), 'w')
	file.write(dis)
Beispiel #44
0
def test_bad_constraints():
    default_args.lp = 1000
    roster = run(POSITIONS[NFL], NFL, [], default_args, True)
    assert roster is None