Пример #1
0
def test_get_people():
    room = Room()

    room.remove_person(datetime.now(), 0)
    assert (room.get_people() == 0)

    room.add_person(datetime.now(), 0)
    assert (room.get_people() == 1)

    room.remove_person(datetime.now(), 0)
    assert (room.get_people() == 0)

    room.add_person(datetime.now(), 0)
    assert (room.get_people() == 1)

    room.add_person(datetime.now(), 0)
    assert (room.get_people() == 2)

    room.remove_person(datetime.now(), 0)
    assert (room.get_people() == 1)
Пример #2
0
def test_get_people():
    room = Room()

    room.remove_person(datetime.now(), 0)
    assert(room.get_people() == 0)

    room.add_person(datetime.now(), 0)
    assert(room.get_people() == 1)

    room.remove_person(datetime.now(), 0)
    assert(room.get_people() == 0)

    room.add_person(datetime.now(), 0)
    assert(room.get_people() == 1)

    room.add_person(datetime.now(), 0)
    assert(room.get_people() == 2)

    room.remove_person(datetime.now(), 0)
    assert(room.get_people() == 1)
Пример #3
0
    def add_person(name, role, allocate="N"):
        """
        Add Person and allocate random room.

        This method adds a person to the Amity System and immediately
        allocates the person a random room.

        filenameeters
        ----------
        name : str
            This is a string representing the full name of the person.
        role : str
            This is a string of the person's role.
        allocate : str
            This is a boolean string that can either be "N" for "No"
            or "Y" for "Yes". It tells us if the person needs
            accommodation.

        Returns
        -------
        string
            This is a string showing success or failure of the operation.

        """
        if not isinstance(name, str) or not isinstance(
                role, str) or not isinstance(allocate, str):
            return TypeError("This method only accepts strings as the input.")
        else:
            all_persons = Person.total_persons
            creation_errors = []
            msg = ''
            given_office = ''
            given_ls = ''
            if allocate != "Y" and allocate != "N":
                creation_errors.append("Allocate only accepts 'Y' or 'N'")
            if role == "Staff":
                temp_staff = Staff(name)
                if allocate == "Y":
                    creation_errors.append(
                        "Cannot allocate Staff a living space")
                given_office = Room.add_person(temp_staff.person_id, "Staff",
                                               "Office")
                if Room.error:
                    creation_errors.append(Room.error)
            elif role == "Fellow":
                temp_fellow = Fellow(name)
                if allocate == "Y":
                    Person.persons["Fellows"][
                        temp_fellow.person_id]['Boarding'] = 'Y'
                    given_office = Room.add_person(temp_fellow.person_id,
                                                   "Fellows", "Office", "Y")
                    if Room.error:
                        creation_errors.append(Room.error)
                    given_ls = Room.add_person(temp_fellow.person_id,
                                               "Fellows", "Living Space", "Y")
                elif allocate == "N":
                    given_office = Room.add_person(temp_fellow.person_id,
                                                   "Fellows", "Office")
                if Room.error:
                    creation_errors.append(Room.error)
            else:
                return TypeError(
                    "Please check that the entered role is either 'Fellow' or 'Staff'"
                )
            new_all_persons = Person.total_persons
            if creation_errors and new_all_persons - all_persons >= 1:
                for item in creation_errors:
                    msg = msg + "\n- " + item
                return "\nThe " + role + ", " + name + " has been added successfuly but with the following problem(s):" + msg
            else:
                msg = "\nThe " + role + ", " + name + " has been added "
                msg += "successfuly and given the following "
                if given_ls:
                    msg += "rooms:-"
                else:
                    msg += "room:-"
                msg += "\n1. Office       --> " + given_office.capitalize()
                if given_ls:
                    msg += "\n2. Living Space --> " + given_ls.capitalize()
                msg += "\n"
                return msg