Ejemplo n.º 1
0
class TestMafiaOrganizationKillMemberCase3MultiLevelsKillLevel2(TestCase):
    def setUp(self):
        # Given
        self.big_boss = Gangster('Big Boss', 21)
        self.g1 = Gangster('Gangster', 20, 'Location Gangster')
        self.g2 = Gangster('Gangster 2', 30, 'Location Gangster 2')
        self.g3 = Gangster('Gangster 3', 32, 'Location Gangster 3')

        self.mog = MafiaOrganization(self.big_boss)
        self.mog.add_under(self.big_boss, self.g1)
        self.mog.add_under(self.g1, self.g2)
        self.mog.add_under(self.g1, self.g3)

        # When
        self.mog.kill_member('Gangster')

    def test_killed_member_is_no_longer_in_organization(self):
        self.assertIsNone(self.mog.find_by_name('Gangster'))

    def test_killed_member_subordinates_is_still_in_organization(self):
        self.assertIsInstance(self.mog.find_by_name('Gangster 2'), Gangster)
        self.assertIsInstance(self.mog.find_by_name('Gangster 3'), Gangster)

    def test_killed_member_oldest_subordinate_has_big_boss_as_a_new_boss(self):
        self.assertEquals(self.g3.get_boss(), self.mog.get_big_boss())

    def test_killed_member_youngest_subordinate_has_a_new_boss(self):
        self.assertEquals(self.g2.get_boss(), self.g3)

    def test_all_subordinates_have_unknown_location(self):
        self.assertEquals(self.g2.location, GangsterLocation.UNKNOWN)
        self.assertEquals(self.g3.location, GangsterLocation.UNKNOWN)

    def test_correct_organization_count(self):
        self.assertEquals(self.mog.members_count(), 3)
Ejemplo n.º 2
0
class TestMafiaOrganizationSendMemberToJailCase3MultiLevelsKillLevel2(TestCase):
    def setUp(self):
        # Given
        self.big_boss = Gangster('Big Boss', 21)
        self.g1 = Gangster('Gangster', 20, 'Location Gangster')
        self.g2 = Gangster('Gangster 2', 30, 'Location Gangster 2')
        self.g3 = Gangster('Gangster 3', 32, 'Location Gangster 3')

        self.mog = MafiaOrganization(self.big_boss)
        self.mog.add_under(self.big_boss, self.g1)
        self.mog.add_under(self.g1, self.g2)
        self.mog.add_under(self.g1, self.g3)

        # When
        self.mog.send_member_to_jail('Gangster')

    def test_send_member_to_jail_is_still_in_organization(self):
        self.assertIsInstance(self.mog.find_by_name('Gangster'), Gangster)

    def test_send_member_to_jail_is_no_longer_found_by_is_member_of_organization(self):
        self.assertFalse(self.mog.is_member_of_organization('Gangster'))

    def test_send_member_to_jail_oldest_subordinate_has_big_boss_as_a_new_boss(self):
        self.assertEquals(self.g3.get_boss(), self.mog.get_big_boss())

    def test_send_member_to_jail_youngest_subordinate_has_a_new_boss(self):
        self.assertEquals(self.g2.get_boss(), self.g3)

    def test_correct_organization_count(self):
        self.assertEquals(self.mog.members_count(), 4)
Ejemplo n.º 3
0
class TestMafiaOrganizationKillMemberCase3LevelsKillLevel1(TestCase):
    def setUp(self):
        # Given
        self.big_boss = Gangster('Big Boss', 21, 'Location Big Boss')
        self.g1 = Gangster('Gangster', 20, 'Location Gangster')
        self.g2 = Gangster('Gangster 2', 20, 'Location Gangster 2')

        self.mog = MafiaOrganization(self.big_boss)
        self.mog.add_under(self.big_boss, self.g1)
        self.mog.add_under(self.g1, self.g2)

        #When
        self.mog.kill_member('Big Boss')

    def test_killed_member_is_no_longer_in_organization(self):
        self.assertIsNone(self.mog.find_by_name('Big Boss'))

    def test_killed_member_subordinate_is_still_in_organization(self):
        self.assertIsInstance(self.mog.find_by_name('Gangster'), Gangster)

    def test_killed_member_subordinate_is_the_new_big_boss(self):
        self.assertEquals(self.g1, self.mog.get_big_boss())

    def test_the_new_big_boss_doesnt_have_a_boss(self):
        self.assertIsNone(self.g1.get_boss())

    def test_killed_member_subordinate_has_unknown_location(self):
        self.assertEquals(self.g1.location, GangsterLocation.UNKNOWN)

    def test_correct_organization_count(self):
        self.assertEquals(self.mog.members_count(), 2)
Ejemplo n.º 4
0
class TestMafiaOrganization(TestCase):
    def setUp(self):
        self.big_boss = Gangster('Big Boss', 21)
        self.mog = MafiaOrganization(self.big_boss)

    def test_constructor_accepts_only_a_gangster_as_big_boss(self):
        self.assertRaises(Exception, MafiaOrganization, '__big_boss')

    def test_constructor_creates_new_organization_instance(self):
        self.assertIsInstance(self.mog, MafiaOrganization)

    def test_get_big_boss_return_the_correct_big_boss(self):
        self.assertEquals(self.mog.get_big_boss(), self.big_boss)

    def test_set_big_boss_sets_correct_big_boss(self):
        big_boss2 = Gangster('Big Boss 2', 22)
        self.mog.set_big_boss(big_boss2)

        self.assertEquals(self.mog.get_big_boss(), big_boss2)

    def test_set_big_boss_sets_correct_big_boss_organization(self):
        self.assertEquals(self.mog.get_big_boss().organization, self.mog)