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)
class SevenRedsTest(unittest.TestCase): nrnd = NonRandom(1) # rolls 1, Odd, Red wh = wheel.Wheel(nrnd) bb = binbuilder.BinBuilder() bb.buildBins(wh) t = table.Table(1000) game = roulettegame.RouletteGame(wh, t) pl = players.SevenReds(t) pl.setStake(100) pl.setRounds(10) def test1_init(self): ''' Tests the initialization of the Martingale Player. Checks initial variables. ''' self.assertEqual(self.pl.stake, 100) self.assertEqual(self.pl.roundsToGo, 10) self.assertEqual(self.pl.lossCount, 0) self.assertEqual(self.pl.betMultiple, 1) self.assertEqual(self.pl.redCount, 0) def test2_roll6reds(self): for roll in range(6): self.game.cycle(self.pl) self.assertEqual(self.pl.redCount, 6) def test3_roll2reds(self): for roll in range(2): self.game.cycle(self.pl) self.assertEqual(self.pl.redCount, 1) self.assertEqual(self.pl.betMultiple, 2)
class PlayerTest(unittest.TestCase): t = table.Table(100) def test1_setstake(self): ''' Tests the initialization of the player's stake ''' pl = players.Player(self.t) self.assertEqual(pl.stake, 0) pl.setStake(100) self.assertEqual(pl.stake, 100) def test2_setrounds(self): ''' Tests the initialization of the number of rounds to go. ''' pl = players.Player(self.t) self.assertEqual(pl.roundsToGo, 0) pl.setRounds(100) self.assertEqual(pl.roundsToGo, 100) def test3_playing(self): ''' Tests the .playing() method for various cases. ''' pl = players.Player(self.t) self.assertFalse(pl.playing()) # stake == 0, rounds to go == 0 pl.setStake(100) self.assertFalse(pl.playing()) # stake > 0, rounds to go == 0 pl.setRounds(10) self.assertTrue(pl.playing()) # stake > 0, rounds to go > 0 pl.setStake(0) self.assertFalse(pl.playing()) # stake == 0, rounds to go > 0
def test2_gather(self): ''' Tests the simulator.Simulatogather() method. ''' wh = wheel.Wheel() bb = binbuilder.BinBuilder() bb.buildBins(wh) t = table.Table(100) game = roulettegame.RouletteGame(wh, t) pl = players.Passenger57(t) sim = simulator.Simulator(pl, game)
class RandomPlayerTest(unittest.TestCase): #setting up non random generator nrnd = NonRandom(0) # always picks the first Outcome in the set t = table.Table(1000) pl = players.RandomPlayer(t, nrnd) def test1_nonrandomchoice(self): for i, oc in enumerate(self.pl.all_OC): if i == self.nrnd.randint(len(self.pl.all_OC)): self.assertEqual(oc, outcome.Outcome('Number 1', 35)) break
class Passenger57Test(unittest.TestCase): t = table.Table(100) 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 test4_nomorerounds(self): nrnd = NonRandom(2) wh = wheel.Wheel(nrnd) bb = binbuilder.BinBuilder() bb.buildBins(wh) t = table.Table(100) game = roulettegame.RouletteGame(wh, t) pl = players.Passenger57(t) pl.setStake(100) pl.setRounds(10) while pl.playing(): game.cycle(pl) self.assertEqual(pl.roundsToGo, 0)
def test1_session(self): ''' Tests if the simulator.Simulatosession() returns the required list of stakes in a controlled simulation. ''' nrnd = NonRandom(1) wh = wheel.Wheel(nrnd) bb = binbuilder.BinBuilder() bb.buildBins(wh) t = table.Table(100) game = roulettegame.RouletteGame(wh, t) pl = players.Passenger57(t) sim = simulator.Simulator(pl, game) self.assertEqual(sim.session(), [90,80,70,60,50,40,30,20,10,0])
def test1_win(self): ''' Tests winning process. ''' nrnd = NonRandom(2) wh = wheel.Wheel(nrnd) bb = binbuilder.BinBuilder() bb.buildBins(wh) t = table.Table(100) game = roulettegame.RouletteGame(wh, t) pl = players.Passenger57(t) pl.setStake(100) pl.setRounds(10) self.assertEqual(pl.stake, 100) game.cycle(pl) self.assertEqual(pl.stake, 110)
def test3_outofmoney(self): ''' Tests if the cycle breaks when the Player's stake is zero ''' nrnd = NonRandom(1) wh = wheel.Wheel(nrnd) bb = binbuilder.BinBuilder() bb.buildBins(wh) t = table.Table(100) game = roulettegame.RouletteGame(wh, t) pl = players.Passenger57(t) pl.setStake(100) pl.setRounds(10) while pl.playing(): game.cycle(pl) self.assertEqual(pl.stake, 0)
class MartingaleTest(unittest.TestCase): t = table.Table(1000) pl = players.Martingale(t) pl.setStake(100) pl.setRounds(10) def test1_init(self): ''' Tests the initialization of the Martingale Player. Checks initial variables. ''' self.assertEqual(self.pl.stake, 100) self.assertEqual(self.pl.roundsToGo, 10) self.assertEqual(self.pl.lossCount, 0) self.assertEqual(self.pl.betMultiple, 1) 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 test2_win(self): ''' Tests the the change in the bet1Multiple and lossCount variables in a winning condition. ''' bet1 = bet.Bet(self.pl.betMultiple, outcome.Outcome('Black', 1)) self.assertEqual(bet1.amountBet, 4) self.pl.win(bet1) self.assertEqual(self.pl.lossCount, 0) self.assertEqual(self.pl.betMultiple, 1)