示例#1
0
class TestGangsterSubordinates(TestCase):
    def setUp(self):
        self.g = Gangster('Gangster', 44)

        self.gs = Gangster('Subordinate', 43)
        self.g.add_subordinate(self.gs)

    def test_subordinates_counts_returns_correct_count(self):
        self.assertEquals(self.g.subordinates_count(), 1)

    def test_add_subordinate_throws_error_on_not_gangster_instance(self):
        self.assertRaises(Exception, self.g.add_subordinate, 'gigi')

    def test_add_subordinate_can_add_gangster(self):
        self.assertEquals(self.g.subordinates_count(), 1)

    def test_add_subordinate_sets_the_correct_boss_on_gangster(self):
        self.assertEquals(self.gs.get_boss(), self.g)

    def test_subordinates_returns_iterator(self):
        self.assertEquals(self.gs, next(self.g.subordinates()))

    def test_delete_subordinate_throws_error_on_not_gangster_instance(self):
        self.assertRaises(Exception, self.g.delete_subordinate, 'gigi')

    def test_delete_subordinate_when_delete_subordinate_gangster_returns_true(
            self):
        self.assertTrue(self.g.delete_subordinate(self.gs))

    def test_delete_subordinate_when_delete_unknown_gangster_returns_false(
            self):
        ngs = Gangster('Not Subordinate', 43)
        self.assertFalse(self.g.delete_subordinate(ngs))
示例#2
0
class TestGangsterSubordinates(TestCase):
    def setUp(self):
        self.g = Gangster('Gangster', 44)

        self.gs = Gangster('Subordinate', 43)
        self.g.add_subordinate(self.gs)

    def test_subordinates_counts_returns_correct_count(self):
        self.assertEquals(self.g.subordinates_count(), 1)

    def test_add_subordinate_throws_error_on_not_gangster_instance(self):
        self.assertRaises(Exception, self.g.add_subordinate, 'gigi')

    def test_add_subordinate_can_add_gangster(self):
        self.assertEquals(self.g.subordinates_count(), 1)

    def test_add_subordinate_sets_the_correct_boss_on_gangster(self):
        self.assertEquals(self.gs.get_boss(), self.g)

    def test_subordinates_returns_iterator(self):
        self.assertEquals(self.gs, next(self.g.subordinates()))

    def test_delete_subordinate_throws_error_on_not_gangster_instance(self):
        self.assertRaises(Exception, self.g.delete_subordinate, 'gigi')

    def test_delete_subordinate_when_delete_subordinate_gangster_returns_true(self):
        self.assertTrue(self.g.delete_subordinate(self.gs))

    def test_delete_subordinate_when_delete_unknown_gangster_returns_false(self):
        ngs = Gangster('Not Subordinate', 43)
        self.assertFalse(self.g.delete_subordinate(ngs))
示例#3
0
class TestMafiaOrganizationSetMemberToFreedom(TestCase):
    def setUp(self):
        self.big_boss = Gangster('Big Boss', 21)

        self.g1 = Gangster('Gangster', 20)
        self.g2 = Gangster('Gangster 2', 20, 'Location 2')

        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.send_member_to_jail('Gangster')

    def test_set_member_to_freedom_on_unknown_gangster_returns_false(self):
        self.assertFalse(self.mog.set_member_to_freedom('Unknown Gangster'))

    def test_set_member_to_freedom_on_known_gangster_returns_true(self):
        self.assertTrue(self.mog.set_member_to_freedom('Gangster'))

    def test_set_member_to_freedom_sets_freestatus(self):
        self.mog.set_member_to_freedom('Gangster')

        self.assertEquals(self.g1.status, GangsterStatus.FREE)

    def test_set_member_to_freedom_restores_all_subordinates(self):
        self.mog.set_member_to_freedom('Gangster')

        self.assertEquals(self.g1.subordinates_count(), 1)
示例#4
0
class TestMafiaOrganizationSendMemberToJail(TestCase):
    def setUp(self):
        self.big_boss = Gangster('Big Boss', 21)

        self.g1 = Gangster('Gangster', 20)
        self.g2 = Gangster('Gangster 2', 20, 'Location 2')

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

    def test_send_member_to_jail_on_unknown_gangster_returns_false(self):
        self.assertFalse(self.mog.send_member_to_jail('Unknown Gangster'))

    def test_send_member_to_jail_on_known_gangster_returns_true(self):
        self.assertTrue(self.mog.send_member_to_jail('Gangster'))

    def test_send_member_to_jail_sets_injailstatus(self):
        self.mog.send_member_to_jail('Gangster')

        self.assertEquals(self.g1.status, GangsterStatus.INJAIL)

    def test_send_member_to_jail_removes_all_subordinates(self):
        self.mog.send_member_to_jail('Gangster')

        self.assertEquals(self.g1.subordinates_count(), 0)

    def test_send_member_to_jail_doesnt_update_subordinate_location_to_unknown(self):
        self.mog.send_member_to_jail('Gangster')

        self.assertEquals(self.g2.location, 'Location 2')

    def test_send_member_to_jail_update_current_boss_attribute_on_subordinates(self):
        self.mog.send_member_to_jail('Gangster')
        self.assertEquals(self.g2.get_boss(), self.big_boss)

    def test_send_member_to_jail_update_previous_boss_attribute_on_subordinates(self):
        self.mog.send_member_to_jail('Gangster')
        self.assertEquals(self.g2.boss_in_jail, self.g1)