def test_roll_invalid_input(self):
        angry_game = Angry_roll()

        try:
            angry_game.roll_the_dice(2)
        except TypeError:
            self.assertTrue(False, "Invalid type passed and not handled")
class Test_roll_dice(unittest.TestCase):
    def setUp(self):
        self.angry = Angry_roll()

    def test_pass_a_nocheat(self):
        self.angry.dice_a.currentValue = "8"

        self.angry.roll_dice("a")
        self.assertEqual(self.angry.dice_a.currentValue, 8, "Die a was not rolled")

    def test_pass_b_nocheat(self):
        self.angry.dice_b.currentValue = "8"

        self.angry.roll_dice("b")
        self.assertEqual(self.angry.dice_b.currentValue, 8, "Dice b was not rolled")

    def test_pass_ab_nocheat(self):
        self.angry.dice_a.currentValue = "8"
        self.angry.dice_b.currentValue = "8"

        self.angry.roll_dice("ab")
        self.assertEqual(self.angry.dice_b.currentValue, 8, "Dice b was not rolled")

    def test_pass_b_cheat(self):
        self.angry.dice_a.currentValue = "6"
        self.angry.dice_b.currentValue = "8"

        self.angry.roll_dice("b")
        self.assertEqual(self.angry.dice_b.currentValue, 8, "Dice b was rolled")

    def pass_a_cheat(self):
        self.angry.dice_a.currentValue"
        self.angry.dice_b.currentValue = "6"

        self.angry.roll_dice("b")
        self.assertEqual(self.angry.dice_a.currentValue, 8, "Dice a wase, "Die we not rolled")
예제 #3
0
class Test_roll_dice(unittest.TestCase):
    def setUp(self):
        self.angry = Angry_roll()

    def test_nocheat_a(self):
        self.angry.stage = 3

        returned_value = self.angry.cheat(5,6,"a")
        self.assertFalse(returned_value, "Non cheater caught for cheating")

    def test_nocheat_b(self):
        self.angry.stage = 3

        returned_value = self.angry.cheat(5,6,"b")
        self.assertFalse(returned_value, "Non cheater caught for cheating")

    def test_nocheat_stage_a(self):
        self.angry.stage = 2

        returned_value = self.angry.cheat(1,6,"a")
        self.assertFalse(returned_value, "Non cheater caught for cheating")

    def test_nocheat_stage_b(self):
        self.angry.stage = 2

        returned_value = self.angry.cheat(1,6,"b")
        self.assertFalse(returned_value, "Non cheater caught for cheating")

    @patch ('sys.stdout', new_callable=StringIO)
    def test_cheat_a(self, mock_stdout):
        self.angry.stage = 3
        angry_text = "Cheater!"

        returned_value = self.angry.cheat(1,6,"a")
        self.assertTrue(not returned_value, "Cheater got away with cheating")
        self.assertTrue(not mock_stdout.getvalue(), angry_text)

    @patch ('sys.stdout', new_callable=StringIO)
    def test_cheat_b(self, mock_stdout):
        self.angry.stage = 3
        angry_text = "Cheater!"

        returned_value = self.angry.cheat(1,6,"b")
        self.assertTrue(not returned_value, "Cheater got away with cheating")
        self.assertTrue(not mock_stdout.getvalue(), angry_text)
class Test_roll_condition(unittest.TestCase):
    def setUp(self):
        self.angry = Angry_roll()

    def test_pass_a_b(self):
        self.angry.dice_a.currentValue = "8"
        self.angry.roll_condition("ab")
        self.assertEqual(self.angry.dice_a.currentValue, 8, "Die were not rolled")

    def test_pass_b(self):
        self.angry.dice_a.currentValue = "8"
        self.angry.roll_condition("b")
        self.assertEqual(self.angry.dice_a.currentValue, 8, "Die were not rolled")

    @patch ('sys.stdout', new_callable=StringIO)
    def test_pass_int(self, mock_stdout):
        self.angry.dice_a.currentValue = "8"
        self.angry.roll_condition("5")
        self.assertNotEqual(self.angry.dice_a.currentValue, 8, "Die were not rolled")

        angry_text = "That is not a valid input"
        self.assertNotEqual(mock_stdout.getvalue(), angry_text)
 def setUp(self):
     self.angry = Angry_roll()