Exemple #1
0
class ScoreTEst(unittest.TestCase):

    """Test Monster Class score function"""

    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")

    def test_score_init(self):
        """make sure score is initialized."""
        self.assertEqual(0, self.test_monster.victory_points)

    def test_score_ideal(self):
        """make sure score is added."""
        self.assertEqual(5, self.test_monster.score(5))

    def test_winning_score_is_20(self):
        """make sure we set the status to winning if vp equal 20"""
        self.test_monster.score(20)
        self.assertEqual("WINNING", self.test_monster.status)

    def test_winning_score_is_over_20(self):
        """make sure we set the status to winning if vp equal to or exceeds 20"""
        self.test_monster.score(25)
        self.assertEqual("WINNING", self.test_monster.status)

    def test_make_sure_status_doesnt_chage(self):
        """ make sure we aren't greedy with winning status"""
        self.test_monster.score(5)
        self.assertNotEqual("WINNING", self.test_monster.status)

    def test_type_checking(self):
        """ can we handle types!"""
        with self.assertRaises(TypeError):
            self.test_monster.heal("something")
Exemple #2
0
class HealTest(unittest.TestCase):
    """Test the functionality of the Monster class heal function."""

    def setUp(self):
        self.new_monster = Monster("Cookie")

    def tearDown(self):
        del self.new_monster

    def test_heal_health_gt_10(self):
        """
        Call the heal method with 6 to add to the initial value of 10.
        Check that the health attribute remains unchanged.
        """

        health = self.new_monster.health

        # Call function
        self.new_monster.heal(6)

        self.assertEqual(health, self.new_monster.health)

    def test_heal_health_le_10(self):
        """
        Set health to 2. Call the heal method with 6 to add.
        Check that the health attribute changes to 8.
        """

        self.new_monster.health = 2

        # Call function
        self.new_monster.heal(6)

        self.assertEqual(self.new_monster.health, 8)

    def test_heal_negative_health_le_10(self):
        """
        Call the heal method with -6 to add.
        Check that the health attribute changes to 4.
        """

        # Call function
        self.new_monster.heal(-6)

        self.assertEqual(4, self.new_monster.health)

    def test_heal_negative_health_lt_0(self):
        """
        Call the heal method with -16 to add.
        Check that the health attribute changes to -6.
        """

        # Call function
        self.new_monster.heal(-16)

        self.assertEqual(-6, self.new_monster.health)
Exemple #3
0
class HealTest(unittest.TestCase):
    """Test the functionality of the Monster class heal function."""
    def setUp(self):
        self.new_monster = Monster("Cookie")

    def tearDown(self):
        del self.new_monster

    def test_heal_health_gt_10(self):
        """Call the heal method with 6 to add to the initial value of 10.
        Check that the health attribute remains unchanged."""
        health = self.new_monster.health
        self.new_monster.heal(6)
        self.assertEqual(health, self.new_monster.health)

    def test_heal_health_le_10(self):
        """Set health to 2. Call the heal method with 6 to add.
        Check that the health attribute changes to 8."""
        self.new_monster.health = 2
        self.new_monster.heal(6)
        self.assertEqual(self.new_monster.health, 8)

    def test_heal_negative_health_le_10(self):
        """Call the heal method with -6 to add.
        Check that the health attribute changes to 4."""
        self.new_monster.heal(-6)
        self.assertEqual(4, self.new_monster.health)

    def test_heal_negative_health_lt_0(self):
        """Call the heal method with -16 to add.
        Check that the health attribute changes to -6."""
        self.new_monster.heal(-16)
        self.assertEqual(-6, self.new_monster.health)

    def test_heal_str_input(self):
        """Call the heal method with "-16" to add.
        Check that the health attribute remains unchanged."""
        health = self.new_monster.health
        self.new_monster.heal("-16")
        self.assertEqual(health, self.new_monster.health)
Exemple #4
0
class HealTest(unittest.TestCase):

    """Test Monster Class heal function"""

    def setUp(self):
        print(self.shortDescription())
        self.test_monster = Monster("The Boogie Monster")

    def test_init_heal_value(self):
        """test initialized health value"""
        self.assertEqual(10, self.test_monster.health)

    def test_ideal_add_health(self):
        """test adding health, with input that will keep at 10 and below"""
        # we have an unhealthy monster
        self.test_monster.health = 2
        self.assertEqual(10, self.test_monster.heal(8))

    def test_ideal_too_much_health(self):
        """test adding too much health, with input that will keep at 10 and below"""
        # we have an unhealthy monster
        self.test_monster.health = 8
        self.assertEqual(10, self.test_monster.heal(8))

    def test_invalid_input_type(self):
        """test trying to add a bad type."""
        with self.assertRaises(TypeError):
            self.test_monster.heal("something")

    def test_negative_heal(self):
        """we should test for negative health catches"""
        with self.assertRaises(ValueError):
            self.test_monster.heal(-10)
Exemple #5
0
class test_heal(unittest.TestCase):
    def setUp(self):
        self.monsta = Monster()
        self.monsta.health = 5

    #Tests if monster heals
    def test_valid_heal(self):
        health = self.monsta.heal(5)

        self.assertEqual(health, 10, "Heal did not work")

    #Monster should not heal if sum > 10
    def test_invalid_heal(self):
        health = self.monsta.heal(6)

        self.assertNotEqual(health, 11, "Heal should not have worked")

    #Tests invalid output
    @patch ('sys.stdout', new_callable=StringIO)
    def test_attack_die_KO(self, mock_stdout):
        health = self.monsta.attack(6)

        text = "Invalid heal amount"
        self.assertNotEqual(mock_stdout.getValue(), text)
Exemple #6
0
class test_heal(unittest.TestCase):
    def setUp(self):
        self.monsta = Monster()
        self.monsta.health = 5

    #Tests if monster heals
    def test_valid_heal(self):
        health = self.monsta.heal(5)

        self.assertEqual(health, 10, "Heal did not work")

    #Monster should not heal if sum > 10
    def test_invalid_heal(self):
        health = self.monsta.heal(6)

        self.assertNotEqual(health, 11, "Heal should not have worked")

    #Tests invalid output
    @patch('sys.stdout', new_callable=StringIO)
    def test_attack_die_KO(self, mock_stdout):
        health = self.monsta.attack(6)

        text = "Invalid heal amount"
        self.assertNotEqual(mock_stdout.getValue(), text)