Ejemplo n.º 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))
Ejemplo n.º 2
0
class TestMafiaOrganizationFindByName(TestCase):
    def setUp(self):
        self.big_boss = Gangster('Big Boss', 21)
        self.mog = MafiaOrganization(self.big_boss)

    def test_find_by_name_search_for_big_boss(self):
        self.assertEquals(self.mog.find_by_name('Big Boss'), self.big_boss)

    def test_find_by_name_search_for_big_boss_subordinate(self):
        g1 = Gangster('Big Boss Subordinate Level 1', 19)
        self.big_boss.add_subordinate(g1)

        self.assertEquals(self.mog.find_by_name('Big Boss Subordinate Level 1'), g1)

    def test_find_by_name_search_for_gangster_no_matter_its_level_in_organization(self):
        g3 = Gangster('Subordinate Level 3-1', 18)
        g4 = Gangster('Subordinate Level 3-2', 18)

        g2 = Gangster('Subordinate Level 2', 19)
        g2.add_subordinate(g4)
        g2.add_subordinate(g3)

        g1 = Gangster('Big Boss Subordinate Level 1', 20)
        g1.add_subordinate(g2)

        self.big_boss.add_subordinate(g1)

        self.assertEquals(self.mog.find_by_name('Subordinate Level 3-2'), g4)
Ejemplo n.º 3
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))
Ejemplo n.º 4
0
    def test_find_by_name_search_for_gangster_no_matter_its_level_in_organization(self):
        g3 = Gangster('Subordinate Level 3-1', 18)
        g4 = Gangster('Subordinate Level 3-2', 18)

        g2 = Gangster('Subordinate Level 2', 19)
        g2.add_subordinate(g4)
        g2.add_subordinate(g3)

        g1 = Gangster('Big Boss Subordinate Level 1', 20)
        g1.add_subordinate(g2)

        self.big_boss.add_subordinate(g1)

        self.assertEquals(self.mog.find_by_name('Subordinate Level 3-2'), g4)