Ejemplo n.º 1
0
def on_request(ch, method, props, req):
    req_json = json.loads(req)

    teachers = Teachers()
    teachers.add(req_json['teachers'])
    subjects = Subjects()
    subjects.add(req_json['subjects'])
    timeslots = TimeSlots(req_json['timeslots'])

    solver = Solver(teachers, subjects, timeslots)
    solver.solve()

    response = solver.solution

    ch.basic_publish(exchange='',
                     routing_key=props.reply_to,
                     properties=pika.BasicProperties(
                         correlation_id=props.correlation_id
                     ),
                     body=str(response))
    ch.basic_ack(delivery_tag=method.delivery_tag)
Ejemplo n.º 2
0
    def test_solver(self):
        teachers = Teachers()
        teachers.add(['Bob', 'Jill', 'Tim', 'Ben'])
        subjects = Subjects()
        subjects.add(['Sport', 'Art'])
        timeslots = TimeSlots(4)

        solver = Solver(teachers,
                        subjects,
                        timeslots)

        solver.solve()

        self.assertEqual(len(solver.solution.row), 2)
        self.assertEqual(len(solver.solution.col), 4)
        self.assertEqual(len(solver.solution.flat), 8)
        self.assertTrue([num in solver.solution.flat for num in
                         range(len(teachers.store)+1)])

        teachers.add('Jeff')
        with self.assertRaises(ValueError):
            solver = Solver(teachers,
                            subjects,
                            timeslots)