Exemplo n.º 1
0
    def test_visit_room_without_description(self):
        name = "name"
        room = Room(name)

        visit_description = room.Visit()

        self.assertIn(name, visit_description)
Exemplo n.º 2
0
def toMap(mapJSON, resources):
    # Add the explicity rooms
    map = {}
    for name, details in mapJSON.items():
        map[name] = Room(name, details, resources)

    # Find the coordinates of the implicit, empty rooms
    filledCoords = []
    maxX = 0
    maxY = 0
    for roomName in map:
        coord = map[roomName].coordinates
        if coord[0] > maxX: maxX = coord[0]  # Find the maximum X coordinate
        if coord[1] > maxY: maxY = coord[1]  # Find the maximum Y coordinate
        filledCoords.append(coord)

    # Add the implicit, empty rooms
    emptyDesc = {
        'title': 'empty',
        'description': 'empty',
        'connections': {},
        'area': 'empty',
        'icon': '|||',
        'coordinates': [],
        'visited': True
    }
    for i in range(maxX + 1):
        for j in range(maxY + 1):
            if [i, j] not in filledCoords:
                emptyDesc['coordinates'] = [i, j]
                map[f'empty_{i}_{j}'] = Room('empty', emptyDesc, resources)

    return map
Exemplo n.º 3
0
    def test_visit_room_first_time(self):
        name = "name"
        description = "description"
        room = Room(name, description)

        first_visit_description = room.Visit()

        self.assertIn(name, first_visit_description)
        self.assertIn(description, first_visit_description)
Exemplo n.º 4
0
    def test_visit_room_second_time(self):
        name = "name"
        description = "description"
        room = Room(name, description)

        room.Visit()
        second_visit_description = room.Visit()

        self.assertIn(name, second_visit_description)
        self.assertNotIn(description, second_visit_description)
Exemplo n.º 5
0
 def __init__(self, dict):
     self.__room = Room(dict["room_num"], dict["clean_rating"],
                        dict["electrical_appliance"], dict["sex"])
     self.__inventory = Inventory(dict["inventory_name"], dict["name"],
                                  dict["surname"], dict["patronymic"],
                                  dict["amount"], dict["num_in_queue"])
     self.__student = Student(dict["name"], dict["surname"],
                              dict["patronymic"], dict["bd"], dict["email"],
                              dict["faculty"], dict["course"],
                              dict["room_num"], dict["phone_number"],
                              dict["sex"])
Exemplo n.º 6
0
def test_room_with_two_adjacent_rooms_should_return_correct_number_of_ids():
    objectDef = {
        'id': 1,
        'name': 'valid',
        'north': 3,
        'south': 4,
        'objects': []
    }
    room = Room(objectDef)
    assert len(room.getAvailableRooms()) == 2
    assert 4 in room.getAvailableRooms()
    assert 3 in room.getAvailableRooms()
Exemplo n.º 7
0
def main(cmdArguments):
    if len(cmdArguments) <= 0:
        raise ValueError("Usage: python main.py <inputfile>")

    slots = []
    rooms = []
    courses = []
    instructors = []

    with open(cmdArguments[0]) as fp:
        for line in fp:
            if line.startswith("#"):
                # ignore comments in input file
                continue

            lineSections = line.split("=")
            if lineSections[0].strip() == "Slot":
                slots.append(Slot(lineSections[1]))
            elif lineSections[0].strip() == "Room":
                rooms.append(Room(lineSections[1]))
            elif lineSections[0].strip() == "Course":
                courses.append(Course(lineSections[1]))
            elif lineSections[0].strip() == "Instructor":
                instructors.append(Instructor(lineSections[1]))

    algo = GeneticAlgorithm(slots, rooms, courses, instructors)
    algo.initChromosomes(100)
    algo.execute()
Exemplo n.º 8
0
def test_get_contained_items_should_return_correct_overlapping_set():
    objectDef = {
        'id': 1,
        'name': 'valid',
        'objects': [{
            'name': 'Knife'
        }, {
            'name': 'Pillow'
        }, {
            'name': 'Fork'
        }]
    }
    room = Room(objectDef)
    containedItems = room.getContainedItems(['Fork', 'Knife'])
    assert len(containedItems) == 2
    assert 'Fork' in containedItems
    assert 'Knife' in containedItems
Exemplo n.º 9
0
def test_clean_room_with_two_adjacent_rooms_should_correctly_clear_pointers():
    objectDef = {
        'id': 1,
        'name': 'valid',
        'north': 3,
        'south': 4,
        'objects': []
    }
    room = Room(objectDef)
    room.cleanRooms()
    assert room.hasNorthRoom() == False
    assert room.hasSouthRoom() == False
Exemplo n.º 10
0
def test_constructor_without_id_definition_should_raise_exception():
    objectDef = {}
    with pytest.raises(ValueError) as e_info:
        room = Room(objectDef)
    assert 'Room definition should contain attribute id' == str(e_info.value)
Exemplo n.º 11
0
def test_constructor_with_not_well_formed_objects_list_should_return_empty_room(
):
    objectDef = {'id': 1, 'name': 'name', 'objects': ['invalid']}
    room = Room(objectDef)
    assert len(room.getObjects()) == 0
Exemplo n.º 12
0
def test_constructor_with_invalid_objects_list_should_raise_exception():
    objectDef = {'id': 1, 'name': 'name', 'objects': 'invalid'}
    with pytest.raises(ValueError) as e_info:
        room = Room(objectDef)
    assert 'Room\'s definition of contained objects should be a list' == str(
        e_info.value)
Exemplo n.º 13
0
def test_constructor_with_not_numeric_id_definition_should_raise_exception():
    objectDef = {'id': 'invalid'}
    with pytest.raises(ValueError) as e_info:
        room = Room(objectDef)
    assert 'Room identifier should be numeric' == str(e_info.value)
Exemplo n.º 14
0
 def load_board_from_csv(
         csv_file_path: str) -> typing.Dict[typing.Tuple[int, int], Room]:
     return {(i, j): Room(cell)
             for j, row in enumerate(utils.LoadCSV(csv_file_path))
             for i, cell in enumerate(row)}
Exemplo n.º 15
0
    def test_describe_room(self):
        name = "name"
        description = "description"
        room = Room(name, description)

        self.assertTrue(description in room.Describe())
Exemplo n.º 16
0
class StudentFacade:
    def __init__(self, dict):
        self.__room = Room(dict["room_num"], dict["clean_rating"],
                           dict["electrical_appliance"], dict["sex"])
        self.__inventory = Inventory(dict["inventory_name"], dict["name"],
                                     dict["surname"], dict["patronymic"],
                                     dict["amount"], dict["num_in_queue"])
        self.__student = Student(dict["name"], dict["surname"],
                                 dict["patronymic"], dict["bd"], dict["email"],
                                 dict["faculty"], dict["course"],
                                 dict["room_num"], dict["phone_number"],
                                 dict["sex"])

    def getStudentAmount(self):
        return self.__student.studentCount()

    def addStudent(self):
        # TODO write student to room
        stId = self.__student.addStudent()
        self.__room.addStudentToRoom(stId)

    def getRoom(self):
        self.__room.getRoom()

    def setRoom(self):
        self.__room.setRoom()

    # How did this occur here
    def getInventory(self):
        pass

    def getStudent(self):
        return self.__student.get()

    def updateStudent(self, array):
        self.__student.updateStudent()

    def removeStudent(self):
        self.__room.deleteStudentFromRoom(self.getStudent()["id"])
        self.__student.deleteStudent()

    def getAllRooms(self):
        rooms = self.__room.getAllRooms()
        res = []
        for room in rooms:
            temp = {"room_num": room['room'], "students": []}
            for i in room['students']:
                buff = self.__student.getStudentByID(i['stId'])
                temp["students"].append(buff["surname"] + " " + buff["name"] +
                                        " " + buff["patronymic"])
            res.append(temp)
        return res

    def getRoom(self):
        if self.__student.get()["room"] is not (None or ""):
            return self.__student.get()["room"]
        else:
            return "Not Found"

    def getAllStudent(self):
        return self.__student.getAllStudent()

    def getAmount(self):
        return self.__student.getAmount()