class AllocationTestCase(unittest.TestCase):
    """ tests the allocation of rooms to persons """

    def test_allocation_to_rooms(self):
        """ tests the allocation of persons to rooms """
        self.fellow = Person.create(
            'Jee Gikera', 'fellow', wants_accomodation='Y')
        self.staff = Person.create('Chidi Nnadi', 'staff')
        office_room = Office('valhalla')
        living_room = LivingSpace('blue')
        # store person instances for testing
        fellow_only.append(self.fellow)
        persons.append(self.staff)
        persons.append(self.fellow)

        office_results = self.staff.assign_office_space(office_room)
        living_results = self.fellow.assign_living_space(living_room)
        office_room.assign_person(self.staff)
        living_room.assign_person(self.fellow)
        self.assertTrue(self.staff.has_office())
        self.assertTrue(self.fellow.has_living_space())
        self.assertIsInstance(office_results, Office)
        self.assertIsInstance(living_results, LivingSpace)
        self.assertIsNotNone(living_room)
        self.assertIsNotNone(office_room)
        self.assertFalse(living_room.is_occupied())
        self.assertFalse(office_room.is_occupied())
        self.office = Office('GreenHouse')
        self.living = LivingSpace('BlueMoon')
        self.amity = Amity()

        ospace = self.amity.allocate_office_space(self.fellow)
        lspace = self.amity.allocate_living_space(self.fellow)
        allocated = self.office.get_occupants()
        self.assertEquals(self.staff.has_living_space(), False)
        self.assertEquals(self.fellow.has_living_space(), True)
        self.assertIsNotNone(allocated)
        self.assertIsNotNone(ospace)
        self.assertIsNotNone(lspace)

    def test_getting_room_occupants(self):
        """ tests getting a given room's occupants """
        self.amity = Amity()
        office_results = self.amity.allocate_office_space(
            file_path, is_a_file=True)
        living_results = self.amity.allocate_living_space(
            file_path, is_a_file=True)
        office_roomies = office_results[0].get_occupants()
        living_roomies = living_results[0].get_occupants()
        self.assertIsNotNone(office_roomies)
        self.assertIsNotNone(living_roomies)

    def test_getting_all_allocations(self):
        """ tests getting all allocations to the building """
        self.amity = Amity()
        self.amity.allocate_living_space(file_path, is_a_file=True)
        self.amity.allocate_office_space(file_path, is_a_file=True)
        allocations = self.amity.get_allocations()
        print_allocation = self.amity.print_allocations()
        self.assertIsNotNone(allocations)
        self.assertTrue(print_allocation)

    def test_unallocated(self):
        """ test getting unallocated people if any """
        amity = Amity()
        amity.allocate_office_space(file_path, is_a_file=True)
        unalloc = amity.get_unallocated()
        unallocated = amity.unallocated
        # the rooms are currently 10, each taking 4 occupants,
        # therefore we don't have unallocated persons
        self.assertIsNotNone(unalloc)
        self.assertIsNotNone(unallocated)
class AllocationTestCase(unittest.TestCase):
    """ tests the allocation of rooms to persons """
    def test_allocation_to_rooms(self):
        """ tests the allocation of persons to rooms """
        self.fellow = Person.create('Jee Gikera',
                                    'fellow',
                                    wants_accomodation='Y')
        self.staff = Person.create('Chidi Nnadi', 'staff')
        office_room = Office('valhalla')
        living_room = LivingSpace('blue')
        # store person instances for testing
        fellow_only.append(self.fellow)
        persons.append(self.staff)
        persons.append(self.fellow)

        office_results = self.staff.assign_office_space(office_room)
        living_results = self.fellow.assign_living_space(living_room)
        office_room.assign_person(self.staff)
        living_room.assign_person(self.fellow)
        self.assertTrue(self.staff.has_office())
        self.assertTrue(self.fellow.has_living_space())
        self.assertIsInstance(office_results, Office)
        self.assertIsInstance(living_results, LivingSpace)
        self.assertIsNotNone(living_room)
        self.assertIsNotNone(office_room)
        self.assertFalse(living_room.is_occupied())
        self.assertFalse(office_room.is_occupied())
        self.office = Office('GreenHouse')
        self.living = LivingSpace('BlueMoon')
        self.amity = Amity()

        ospace = self.amity.allocate_office_space(self.fellow)
        lspace = self.amity.allocate_living_space(self.fellow)
        allocated = self.office.get_occupants()
        self.assertEquals(self.staff.has_living_space(), False)
        self.assertEquals(self.fellow.has_living_space(), True)
        self.assertIsNotNone(allocated)
        self.assertIsNotNone(ospace)
        self.assertIsNotNone(lspace)

    def test_getting_room_occupants(self):
        """ tests getting a given room's occupants """
        self.amity = Amity()
        office_results = self.amity.allocate_office_space(file_path,
                                                          is_a_file=True)
        living_results = self.amity.allocate_living_space(file_path,
                                                          is_a_file=True)
        office_roomies = office_results[0].get_occupants()
        living_roomies = living_results[0].get_occupants()
        self.assertIsNotNone(office_roomies)
        self.assertIsNotNone(living_roomies)

    def test_getting_all_allocations(self):
        """ tests getting all allocations to the building """
        self.amity = Amity()
        self.amity.allocate_living_space(file_path, is_a_file=True)
        self.amity.allocate_office_space(file_path, is_a_file=True)
        allocations = self.amity.get_allocations()
        print_allocation = self.amity.print_allocations()
        self.assertIsNotNone(allocations)
        self.assertTrue(print_allocation)

    def test_unallocated(self):
        """ test getting unallocated people if any """
        amity = Amity()
        amity.allocate_office_space(file_path, is_a_file=True)
        unalloc = amity.get_unallocated()
        unallocated = amity.unallocated
        # the rooms are currently 10, each taking 4 occupants,
        # therefore we don't have unallocated persons
        self.assertIsNotNone(unalloc)
        self.assertIsNotNone(unallocated)
예제 #3
0
class AmityTest(unittest.TestCase):

    def setUp(self):
        self.amity = Amity()
        self.fellow = Fellow()
        self.Staff = Staff()
        self.office = Office()
        self.livingspace = LivingSpace()

    def test_add_person_fellow(self):
        self.amity.fellows = [{"id":"F16", "name":"Maryanne Waceke","role":"fellow" ,"office":"camelot"}]
        original_length = len(self.amity.fellows)
        self.amity.add_person("Jake", "Mwai", "fellow", "yes")
        self.assertTrue(len(self.amity.fellows) > original_length)

    def test_add_person_staff(self):
        self.amity.staff = []
        original_length = len(self.amity.staff)
        self.amity.add_person("Sally", "Irungu", "staff")
        self.assertTrue(len(self.amity.staff) > original_length)

    def test_add_person_takes_either_role_of_staff_or_fellow(self):
        self.amity.staff = []
        original_length = len(self.amity.staff)
        self.assertEqual(self.amity.add_person("harry", "kimani", 2), "Please enter valid role.")

    def test_add_person_takes_either_yes_or_no_for_wants_accomodaton(self):
        self.amity.fellows = []
        original_length = len(self.amity.fellows)
        with self.assertRaises(ValueError):
            self.amity.add_person("harry", "kimani", "fellow", 3)

    def test_add_person_does_not_allocate_staff_accomodation(self):
        self.amity.staff = []
        original_length = len(self.amity.staff)
        self.amity.add_person("Stella", "Murimi", "staff", "yes")
        self.assertEqual(self.amity.staff[0]["living_space"], None)

    def test_create_room_one_room(self):
        self.amity.offices = []
        original_length = len(self.amity.offices)
        self.amity.create_room("living_space", "narnia")
        self.assertTrue(len(self.amity.offices) > original_length)

    def test_create_room_more_rooms(self):
        self.amity.offices = []
        original_length = len(self.amity.offices)
        self.amity.create_room("living_space", "narnia", "topaz", "emerald")
        self.assertEqual(len(self.amity.offices), original_length+3)

    def test_create_room_takes_either_living_space_or_office_for_type(self):
        # self.amity.offices = [{"name": "camelot", "no_of_members": 1, "max_members": 6}]
        # self.amity.living_spaces = [{"name": "emerald", "no_of_members": 1, "max_members": 4}]
        # offices_original_length = len(self.amity.offices)
        # living_spaces_original_length = len(self.amity.living_spaces)
        # self.amity.create_room("sitting_room", "topaz")
        # self.assertEqual(len(self.amity.offices), offices_original_length)
        self.assertEqual(self.amity.create_room("sitting_room", "narnia"),"Please input valid room type")

    def test_create_room_only_takes_strings_as_room_names(self):
        self.assertEqual(self.amity.create_room("office", 1, 2), "Please enter valid room names.")

    # def test_allocate_office(self):
    #     pass
    def test_allocate_living_space_works(self):
        self.amity.living_spaces = [
            {"name": "emerald", "no_of_members": 1, "max_members": 4}]
        original_occupants = self.amity.living_spaces[0]["no_of_members"]
        self.amity.allocate_living_space("F120", "emerald")
        self.assertTrue(
            self.amity.living_spaces[0]["no_of_members"] > original_occupants)

    def test_allocate_living_space_doesnt_allocate_staff(self):
        # self.amity.living_spaces = [
        #     {"name": "emerald", "no_of_members": 1, "max_members": 4}]
        # original_occupants = self.amity.living_spaces[0]["no_of_members"]
        # self.amity.allocate_living_space("S12", "emerald")
        # self.assertEqual(
        #     self.amity.living_spaces[0]["no_of_members"], original_occupants)
        self.assertEqual(self.amity.allocate_living_space("S12", "emerald"), "Staff cannot be allocated living space.")


    def test_allocate_living_space_doesnt_allocate_beyond_maximum(self):
        self.amity.living_spaces = [
            {"name": "emerald", "no_of_members": 4, "max_members": 4}]
        # original_occupants = self.amity.living_spaces[0]["no_of_members"]
        # self.amity.allocate_living_space("F120", "emerald")
        # self.assertEqual(
        #     self.amity.living_spaces[0]["no_of_members"], original_occupants)
        self.assertEqual(self.amity.allocate_living_space("F120", "emerald"), "Room full.")

    def test_reallocate_office_works(self):
        self.amity.offices = [{"name": "camelot", "no_of_members": 1, "max_members": 6}, {
            "name": "hogwarts", "no_of_members": 0, "max_members": 6}]
        self.amity.fellows = [{"id":"F16", "name":"Maryanne Waceke","role":"fellow" ,"office":"camelot"}]
        original_camelot_occupants = self.amity.offices[0]["no_of_members"]
        original_hogwarts_occupants = self.amity.offices[1]["no_of_members"]
        self.amity.reallocate_office("F16", "hogwarts")
        self.assertTrue(self.amity.offices[0]["no_of_members"]<original_camelot_occupants)
        self.assertTrue(self.amity.offices[1]["no_of_members"]>original_hogwarts_occupants)
예제 #4
0
import os
import sys
import inspect

currentdir = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

from amity import Amity

# exit gracefully when the text file to read is missing
if __name__ == "__main__":
    try:
        arg1 = sys.argv[1]
    except IndexError:
        print("Usage: python sample.py <text file>")
        sys.exit(1)

amity = Amity()
amity.allocate_living_space(sys.argv[1], is_a_file=True)
amity.allocate_office_space(sys.argv[1], is_a_file=True)

amity.get_allocations()
amity.print_allocations()
print amity.get_unallocated()
import os
import sys
import inspect
currentdir = os.path.dirname(os.path.abspath(
    inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

from amity import Amity


# exit gracefully when the text file to read is missing
if __name__ == "__main__":
    try:
        arg1 = sys.argv[1]
    except IndexError:
        print ("Usage: python sample.py <text file>")
        sys.exit(1)

amity = Amity()
amity.allocate_living_space(sys.argv[1], is_a_file=True)
amity.allocate_office_space(sys.argv[1], is_a_file=True)

amity.get_allocations()
amity.print_allocations()
print amity.get_unallocated()