class TableTest(unittest.TestCase): oc1 = outcome.Outcome('Line 0-00-1-2-3', 5) oc2 = outcome.Outcome('Red', 1) bet1 = bet.Bet(110, oc1) bet2 = bet.Bet(5, oc2) t0 = table.Table(100) t1 = table.Table(100) t2 = table.Table(200) def test1_isvalid(self): ''' Tests the bet validity check The first test will test for a True case the second one tests for False ''' self.assertTrue(self.t1.isValid(self.bet2)) self.assertFalse(self.t1.isValid(self.bet1)) def test2_placebet(self): ''' Tests the correct handling of bet placing It adds a valid bet and checks if it was stored. Then it adds an another one making it invalid and expects the custom Exception ''' self.t0.placeBet(self.bet2) self.assertEqual(self.t0.bets, [self.bet2]) self.assertRaises(table.InvalidBet, self.t0.placeBet, self.bet1) def test3_str(self): ''' Tests the str output of the class It checks it with no bets added Then it tests with one added, then with two added. ''' self.assertEqual(self.t2.__str__(), '') self.t2.placeBet(self.bet1) self.assertEqual(self.t2.__str__(), '$110 on Line 0-00-1-2-3 (odds 5:1)') self.t2.placeBet(self.bet2) self.assertEqual(self.t2.__str__(), '$110 on Line 0-00-1-2-3 (odds 5:1), $5 on Red (odds 1:1)') def test4_iter(self): ''' Iterates through a Table object ''' bets = [] for bet in self.t2: bets.append(bet) self.assertEqual(bets, [self.bet1, self.bet2]) def test5_clearbets(self): self.assertTrue(len(self.t2.bets) > 0) self.t2.clearBets() self.assertEqual(len(self.t2.bets), 0)
def test2_loss(self): ''' Tests the the change in the bet1Multiple and lossCount variables in a losing condition. ''' bet1 = bet.Bet(self.pl.betMultiple, outcome.Outcome('Black', 1)) self.assertEqual(bet1.amountBet, 1) self.pl.lose(bet1) self.assertEqual(self.pl.lossCount, 1) self.assertEqual(self.pl.betMultiple, 2) bet1 = bet.Bet(self.pl.betMultiple, outcome.Outcome('Black', 1)) self.assertEqual(bet1.amountBet, 2) self.pl.lose(bet1) self.assertEqual(self.pl.lossCount, 2) self.assertEqual(self.pl.betMultiple, 4)
def test1_placebet(self): ''' Tests if the bet placed by the player is correctly stored in the Table object. ''' pl = players.Passenger57(self.t) pl.setStake(100) pl.placeBets() self.assertEqual(self.t.bets[0], bet.Bet(10, outcome.Outcome('Black', 1)))
def test_str(self): bet3 = bet.Bet(100, self.oc2) self.assertEqual(bet3.__str__(), '$100 on Red (odds 1:1)')
def test_losebet(self): bet2 = bet.Bet(10, self.oc2) self.assertEqual(bet2.loseAmount(), -10)
def test_winbet(self): bet1 = bet.Bet(100, self.oc1) self.assertEqual(bet1.winAmount(), 500)