Пример #1
0
class MyTestCase(unittest.TestCase):
    @classmethod
    def setUp(self) -> None:
        self.t = Table([])
        self.w = Wheel()
        binBuilder = BinBuilder(self.w)
        binBuilder.buildBins()
        self.blackOutcome = self.w.getOutcomeByName('black')
        self.redOutcome = self.w.getOutcomeByName('red')
        self.blackOutcomeBin = Bin([self.blackOutcome])
        self.redOutcomeBin = Bin([self.redOutcome])
        self.m = Martingale(self.t, self.w)
        self.m.isPlaying = MagicMock(return_value=True)
        self.g = Game(self.t, self.w)

    def testLossCount(self):
        self.assertEqual(self.m.lossCount, 0)
        self.m.lose(Bet(1, self.blackOutcome))
        self.assertEqual(self.m.lossCount, 1)

    def testWinLossCountInit(self):
        myBet = Bet(1, self.blackOutcome)
        self.m.lose(myBet)
        self.m.win(myBet)
        self.assertEqual(self.m.lossCount, 0)

    def testStakeOnLoseAndWin(self):
        self.assertEqual(self.m.stake, 1000)
        myBet = Bet(10, self.blackOutcome)
        self.m.placeBets()
        self.m.lose(myBet)
        self.assertEqual(self.m.stake, 990)
        self.m.placeBets()
        self.m.win(myBet)
        self.assertEqual(self.m.stake, 990)
        self.m.placeBets()
        self.m.win(myBet)
        self.assertEqual(self.m.stake, 1000)

    def test_placeBets(self):
        wheelSpins = [
            self.redOutcomeBin, self.redOutcomeBin, self.redOutcomeBin,
            self.blackOutcomeBin, self.blackOutcomeBin
        ]
        correctLossCount = [0, 1, 2, 3, 0]
        zipped = zip(wheelSpins, correctLossCount)
        for z in zipped:
            self.assertEqual(self.m.lossCount, z[1])
            self.w.next = MagicMock(return_value=z[0])
            self.g.cycle(self.m)
Пример #2
0
class TestGame(unittest.TestCase):
    @classmethod
    def setUp(self) -> None:
        self.w = Wheel()
        binBuilder = BinBuilder(self.w)
        binBuilder.buildBins()
        self.t = Table([])
        self.g = Game(self.t, self.w)

    def test_init(self):
        self.assertTrue(type(self.g) == Game)

    def test_cycle_placeBets(self):
        p1 = Passenger57(self.t, self.w)
        p1.placeBets = MagicMock()
        self.w.next = MagicMock(return_value=self.w.getOutcomeByName('black'))
        p1.isPlaying = MagicMock(return_value=True)

        self.g.cycle(p1)

        p1.placeBets.assert_called()
        self.w.next.assert_called()

    def test_cycle_win_lose(self):
        p1 = Passenger57(self.t, self.w)
        p1.win = MagicMock()
        p1.lose = MagicMock()
        black = self.w.getOutcomeByName('black')
        self.w.next = MagicMock(return_value=Bin([black]))
        p1.isPlaying = MagicMock(return_value=True)

        self.g.cycle(p1)

        p1.win.assert_called()
        p1.lose().assert_not_called()

    def testMockWheel(self):
        self.w.next = MagicMock(return_value=self.w.getOutcomeByName('black'))
        self.assertTrue(self.w.next().name == 'black')

    def testIsPlaying(self):
        p1 = Passenger57(self.t, self.w)
        p1.isPlaying = MagicMock(return_value=False)
        p1.placeBets = MagicMock()
        self.w.next = MagicMock(return_value=self.w.getOutcomeByName('black'))

        self.g.cycle(p1)
        p1.placeBets.assert_not_called()
Пример #3
0
 def testGetOutcomeByName(self):
     # arrange
     w = Wheel()
     o = Outcome('red', 1)
     # act
     w.addOutcome(5, o)
     # assert
     self.assertEqual(o, w.getOutcomeByName('red'))
Пример #4
0
class MyTestCase(unittest.TestCase):
    @classmethod
    def setUp(self) -> None:
        self.w = Wheel()
        bb = BinBuilder(self.w)
        bb.buildBins()
        self.t = Table()
        self.p = Player(self.t, self.w)

    def test_default_budget(self):
        self.assertEqual(self.p.budget,
                         self.p.BUDGET_MIN_DEFAULT_MULTIPLIER * self.t.minimum)

    def test_default_duration(self):
        self.assertEqual(self.p.duration, self.p.DURATIONS_MIN_DEFAULT)

    def test_win(self):
        budgetBefore = self.p.budget
        outcome = self.w.getOutcomeByName("0")
        bet = Bet(self.t.minimum, outcome)
        self.p.win(bet)
        self.assertEqual(self.p.budget,
                         budgetBefore + bet.amount * (outcome.odds + 1))

    def test_placeBets_BudgetReduction(self):
        budgetBefore = self.p.budget
        self.p.placeBets()
        self.assertEqual(budgetBefore, self.p.budget + self.t.minimum)

    def test_placeBets_DurationReduction(self):
        durationBefore = self.p.duration
        self.p.placeBets()
        self.assertEqual(durationBefore, self.p.duration + 1)

    def test_isPlaying_trueWhenDurationAndBudgetpositive(self):
        self.assertTrue(self.p.isPlaying())

    def test_isPlaying_falseWhenDurationAndBudgetNegative(self):
        self.p.budget = 0
        self.assertFalse(self.p.isPlaying())
        self.p.budget = 100
        self.p.duration = 0
        self.assertFalse(self.p.isPlaying())

        if __name__ == '__main__':
            unittest.main()
Пример #5
0
 def __init__(self, table: Table, wheel: Wheel) -> None:
     super().__init__(table, wheel)
     self.black = wheel.getOutcomeByName(Passenger57.BLACK_OUTCOME_NAME)