def test_buy_error(self): owner = Owner(20, [RosterSlot.QB, RosterSlot.QB, RosterSlot.TE], 0) player_qb = Player("blahQB", Position.QB, 1, 0) player_te = Player("blahTE", Position.TE, 1, 1) player_te2 = Player("blahTE2", Position.TE, 2, 2) player_wr = Player("blahWR", Position.WR, 1, 3) with self.assertRaises(InsufficientFundsError): owner.buy(player_qb, 21) with self.assertRaises(NoValidRosterSlotError): owner.buy(player_wr, 3) with self.assertRaises(NoValidRosterSlotError): owner.buy(player_te, 3) owner.buy(player_te2, 3) with self.assertRaises(AlreadyPurchasedError): owner.buy(player_qb, 3) player_qb_dupe = Player("blahQB", Position.QB, 1, 0) owner.buy(player_qb_dupe, 3) owner = Owner(20, [RosterSlot.QB, RosterSlot.TE], 0) with self.assertRaises(InsufficientFundsError): owner.buy(player_qb, 10) owner.buy(player_te, 11)
def test_buy(self): owner = Owner(20, [RosterSlot.WR, RosterSlot.WRRBTE, RosterSlot.BN], 0) player_wr = Player("blahWR", Position.WR, 1, 0) player_wr2 = Player("blahWR2", Position.WR, 2, 1) player_te = Player("blahTE", Position.TE, 3, 2) owner.buy(player_wr, 5) self.assertEqual(15, owner.money) self.assertEqual(player_wr, owner.roster[0].occupant) owner.buy(player_wr2, 5) # higher value WR should replace the existing qb self.assertEqual(player_wr2, owner.roster[0].occupant) self.assertEqual(player_wr, owner.roster[1].occupant) self.assertEqual(10, owner.money) owner.buy(player_te, 5) self.assertEqual(5, owner.money) # this should displace the WRRBTE slot, leaving the low-value wr in the bench slot self.assertEqual(player_wr2, owner.roster[0].occupant) self.assertEqual(player_te, owner.roster[1].occupant) self.assertEqual(player_wr, owner.roster[2].occupant) self.assertEqual(5, owner.money) # we should still get the same outcome even if we do it in a different order owner = Owner(20, [RosterSlot.WR, RosterSlot.WRRBTE, RosterSlot.BN], 0) owner.buy(player_te, 5) owner.buy(player_wr2, 5) owner.buy(player_wr, 5) self.assertEqual(player_wr2, owner.roster[0].occupant) self.assertEqual(player_te, owner.roster[1].occupant) self.assertEqual(player_wr, owner.roster[2].occupant) self.assertEqual(5, owner.money)
def test_max_bid(self): owner = Owner(20, [RosterSlot.QB, RosterSlot.QB, RosterSlot.TE], 0) player_qb = Player("blahQB", Position.QB, 1, 0) player_qb2 = Player("blahQB2", Position.QB, 1, 1) self.assertEqual(18, owner.max_bid()) owner.buy(player_qb, 5) self.assertEqual(14, owner.max_bid()) owner.buy(player_qb2, 5) self.assertEqual(10, owner.max_bid())
def test_can_buy(self): owner = Owner(20, [RosterSlot.QB, RosterSlot.QB, RosterSlot.TE], 0) player_qb = Player("blahQB", Position.QB, 1, 0) player_te = Player("blahTE", Position.TE, 1, 1) player_wr = Player("blahWR", Position.WR, 1, 2) self.assertFalse(owner.can_buy(player_qb, 21)) self.assertFalse(owner.can_buy(player_wr, 3)) owner.buy(player_te, 3) self.assertFalse(owner.can_buy(player_te, 3)) owner.buy(player_qb, 3) player_qb_dupe = Player("blahQB", Position.QB, 1, 0) self.assertFalse(owner.can_buy(player_qb_dupe, 1)) owner = Owner(20, [RosterSlot.QB, RosterSlot.TE], 0) owner.buy(player_qb, 10) player_qb2 = Player("blahQB2", Position.QB, 4, 4) self.assertFalse(owner.can_buy(player_qb2, 5)) self.assertFalse(owner.can_buy(player_te, 11))
def test_accepts(self): pos1 = RosterSlot.QB pos3 = RosterSlot.WRRBTE pos11 = RosterSlot.BN player_qb = Player("blahQB", Position.QB, 1, 0) player_wr = Player("blahWR", Position.WR, 1, 1) player_rb = Player("blahRB", Position.RB, 1, 2) player_te = Player("blahTE", Position.TE, 1, 3) player_cb = Player("blahCB", Position.CB, 1, 4) player_s = Player("blahS", Position.S, 1, 5) self.assertTrue(pos1.accepts(player_qb)) self.assertTrue(pos3.accepts(player_wr)) self.assertTrue(pos3.accepts(player_rb)) self.assertTrue(pos3.accepts(player_te)) self.assertTrue(pos11.accepts(player_qb)) self.assertTrue(pos11.accepts(player_cb)) self.assertTrue(pos11.accepts(player_s)) self.assertFalse(pos1.accepts(player_s)) self.assertFalse(pos1.accepts(player_s)) self.assertFalse(pos1.accepts(player_te)) self.assertFalse(pos1.accepts(player_cb)) self.assertFalse(pos3.accepts(player_s))
def test_scoring_value(self): owner = Owner(20, [RosterSlot.WR, RosterSlot.WRRBTE, RosterSlot.BN], 0) player_wr = Player("blahWR", Position.WR, 1, 0) player_wr2 = Player("blahWR2", Position.WR, 2, 1) player_te = Player("blahTE", Position.TE, 3, 2) owner.buy(player_te, 5) owner.buy(player_wr2, 5) owner.buy(player_wr, 5) self.assertAlmostEqual(5, owner.start_value()) self.assertAlmostEqual(1, owner.bench_value()) self.assertAlmostEqual(3, owner.score(.5)) owner = Owner(20, [RosterSlot.WR, RosterSlot.WRRBTE, RosterSlot.BN], 0) player_wr = Player("blahWR", Position.WR, 5, 0) player_wr2 = Player("blahWR2", Position.WR, 10, 1) player_te = Player("blahTE", Position.TE, 20, 2) owner.buy(player_te, 5) owner.buy(player_wr2, 5) owner.buy(player_wr, 5) self.assertAlmostEqual(30, owner.start_value()) self.assertAlmostEqual(5, owner.bench_value()) self.assertAlmostEqual(17.5, owner.score(.5))
def setUp(self): # Starts a 3 player game, 200 to spend roster_slots = [ RosterSlot.QB, RosterSlot.RB, RosterSlot.RB, RosterSlot.WR, RosterSlot.WR, RosterSlot.WRRBTE, RosterSlot.TE, RosterSlot.K, RosterSlot.DST, RosterSlot.BN, RosterSlot.BN ] self.players = [ Player("GoodQB1", Position.QB, 35, 0), Player("GoodQB2", Position.QB, 30, 1), Player("GoodQB3", Position.QB, 25, 2), Player("GoodQB4", Position.QB, 20, 3), Player("GoodQB5", Position.QB, 15, 4), Player("GoodQB6", Position.QB, 10, 5), Player("GoodWR1", Position.WR, 50, 6), Player("GoodWR2", Position.WR, 48, 7), Player("GoodWR3", Position.WR, 46, 8), Player("OkayWR1", Position.WR, 40, 9), Player("OkayWR2", Position.WR, 38, 10), Player("OkayWR3", Position.WR, 36, 11), Player("BadWR1", Position.WR, 20, 12), Player("BadWR2", Position.WR, 15, 13), Player("BadWR3", Position.WR, 5, 14), Player("GoodRB1", Position.RB, 45, 15), Player("GoodRB2", Position.RB, 43, 16), Player("GoodRB3", Position.RB, 41, 17), Player("OkayRB1", Position.RB, 35, 18), Player("OkayRB2", Position.RB, 33, 19), Player("OkayRB3", Position.RB, 31, 20), Player("BadRB1", Position.RB, 15, 21), Player("BadRB2", Position.RB, 10, 22), Player("BadRB3", Position.RB, 5, 23), Player("GoodTE1", Position.TE, 35, 24), Player("GoodTE2", Position.TE, 30, 25), Player("GoodTE3", Position.TE, 25, 26), Player("GoodTE4", Position.TE, 10, 27), Player("GoodTE5", Position.TE, 8, 28), Player("GoodTE6", Position.TE, 5, 29), Player("GoodK1", Position.K, 10, 30), Player("GoodK2", Position.K, 9, 31), Player("GoodK3", Position.K, 8, 32), Player("GoodK4", Position.K, 7, 33), Player("GoodK5", Position.K, 6, 34), Player("GoodK6", Position.K, 5, 35), Player("GoodDST1", Position.DST, 10, 36), Player("GoodDST2", Position.DST, 9, 37), Player("GoodDST3", Position.DST, 8, 38), Player("GoodDST4", Position.DST, 7, 39), Player("GoodDST5", Position.DST, 6, 40), Player("GoodDST6", Position.DST, 5, 41), ] self.auction = Auction(self.players, 3, 200, roster_slots)