コード例 #1
0
class TestCreateRoom(unittest.TestCase):
    def setUp(self):
        self.amity = Amity()

    #test_if_can_add_more than one room
    #test_if_duplicate_entries_not_added

    def test_whether_office_already_exists(self):
        create1 = self.amity.create_room("O", "asgard")
        self.assertEqual("Room already exists",
                         create1,
                         msg="Duplicate room is being created")

    def test_if_office_created(self):
        # print (self.amity.offices[0].current_occupants)
        self.assertEqual(
            self.amity.create_room("O", "cave"),
            "We have successfully created a new office called: CAVE",
            msg="Office CANNOT be created successfully")

    def test_whether_livingspace_already_exists(self):
        create1 = self.amity.create_room("L", "statehouse")
        self.assertEqual("Room already exists",
                         create1,
                         msg="Duplicate room is being created")

    def test_if_livingspace_created(self):
        self.assertEqual(self.amity.create_room("L", "cave"),
                         "New living quarters ( CAVE ) successfully created!",
                         msg="Office CANNOT be created successfully")
コード例 #2
0
class TestLoadPeople(unittest.TestCase):
    def setUp(self):
        self.amity = Amity()

    def test_file_created(self):
        self.assertTrue(os.path.exists("file.txt"))  #change filename

    def test_if_file_is_not_already_open(self):
        self.assertEqual(self.amity.load_people(),
                         "file is already opened",
                         msg="File not closed being reopened"
                         )  #to correct for with parameter

    def test_if_file_does_not_exists(self):
        self.assertEqual(self.amity.load_people(), "file does not exist")

    def test_whether_input_is_txt_file(self):
        pass

    def test_if_input_file_is_not_blank(self):
        self.assertEqual(self.amity.load_people(),
                         "File may be empty or in incorrect format")

    def test_if_input_file_in_correct_format(self):
        self.assertEqual(self.amity.load_people(),
                         "File may be empty or in incorrect format")
コード例 #3
0
class TestPrintRoom(unittest.TestCase):
    def setUp(self):
        self.room = Room("statehouse")
        self.person = Person()
        self.amity = Amity()
        self.amity.reallocate_person(1, "statehouse")

    def test_if_room_exists(self):
        self.assertTrue(self.room.name in rooms, msg="Room does NOT exist")

    def test_room_prints_all_members(self):
        self.assertTrue(len(self.room.current_occupants) == 1,
                        msg="All members not printed successfully")
コード例 #4
0
class TestAddPerson(unittest.TestCase):
    def setUp(self):
        self.amity = Amity()

    def test_whether_fellow_already_exists(self):
        create = self.amity.add_person("WONDERWOMAN", "FELLOW", "Y")
        self.assertEqual("Person already exists",
                         create,
                         msg="Duplicate person being created")

    #test_if_person_identifier_exists
    ## what if 2 people have the same name?

    def test_if_fellow_added(self):
        room = self.amity.create_room("o", "oculus")
        ls = self.amity.create_room("l", "london")
        count = len(self.amity.fellows)
        create = self.amity.add_person("WOLVERINE", "FELLOW", "Y")
        self.assertEqual(len(self.amity.fellows),
                         count + 1,
                         msg="Fellow CANNOT be added successfully")

    def test_whether_staff_already_exists(self):
        create = self.amity.add_person("STRANGE", "STAFF", "N")
        self.assertEqual("Person already exists",
                         create,
                         msg="Duplicate person being created")

    def test_if_staff_added(self):
        room = self.amity.create_room("o", "oculus")
        count = len(self.amity.staff)
        self.amity.add_person("CYBORG", "STAFF", "N")
        import pdb
        pdb.set_trace()
        self.assertEqual(len(self.amity.staff),
                         count + 1,
                         msg="Staff CANNOT be added successfully")

    def test_if_randomly_allocated(self):
        person = self.amity.add_person("CYBORG", "STAFF", "N")
        room = self.amity.create_room("o", "Mombasa")
        self.assertTrue(person in room.current_occupants)
コード例 #5
0
 def setUp(self):
     self.amity = Amity()
コード例 #6
0
 def setUp(self):
     amity = Amity()
     amity.load_people(
     )  #refactor to accept an optional argument for filename
コード例 #7
0
 def setUp(self):
     amity = Amity()
     amity.save_state(
     )  #refactor to accept an optional argument for filename
コード例 #8
0
 def setUp(self):
     self.room = Room("statehouse")
     self.person = Person()
     self.amity = Amity()
     self.amity.reallocate_person(1, "statehouse")