Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.2 kB
6
Indexable
Never
class TestOrderScheduler(unittest.TestCase):

	def setUp(self):
		self.scheduler = OrderScheduler()
		self.agents = [
			Agent(1, 1, 1, (1,1)),
			Agent(1, 1, 1, (1,2)),
			Agent(1, 1, 1, (1,3))
		]

	def test_scheduler_sorts_agents_by_dist_to_order(self):
		order = Order(1, (1,3), 1, 1, 1)

		sortedAgents = self.scheduler.get_sorted_agents_list(order, self.agents)

		self.assertEqual(sortedAgents[2].pos, self.agents[0].pos)
		self.assertEqual(sortedAgents[1].pos, self.agents[1].pos)
		self.assertEqual(sortedAgents[0].pos, self.agents[2].pos)


	def test_scheduler_assigns_closest_agent(self):
		order = Order(1, (1,1), 999, 1, 1)
		agent = self.agents[0]
		self.scheduler.assign_orders([order], self.agents)

		self.assertEqual(agent.currentOrder, order)


	def test_scheduler_assigns_3_agents(self):
		orders = [
			Order(1, (1,1), 999, 1, 1),
			Order(1, (1,1), 999, 1, 1),
			Order(1, (1,1), 999, 1, 1)
		]

		print("before assign_orders call\n")
		assignedAgents = self.scheduler.assign_orders(orders, self.agents)

		print("after assign_orders call\n")
		print("before test case assert\n")
		self.assertEqual(len(assignedAgents), 3)