summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHaidong Ji2019-02-21 21:32:22 -0600
committerHaidong Ji2019-02-21 21:32:22 -0600
commit421f2e783af773712a5e7a799f7cbaca69ab7a21 (patch)
tree1bcc356b41444fcc03bfd84e86d5a91fa3b38c49 /tests
parent602995c859265493dd94996d1626e6de44d512e6 (diff)
Priority queue parallel job processing done!
Not too bad since I worked it out in Java. Good practice of heapq module in Python! A lot of fun :)
Diffstat (limited to 'tests')
-rw-r--r--tests/job_queueTest.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/job_queueTest.py b/tests/job_queueTest.py
new file mode 100644
index 0000000..ac95c35
--- /dev/null
+++ b/tests/job_queueTest.py
@@ -0,0 +1,28 @@
+import unittest
+
+from collections import namedtuple
+
+AssignedJob = namedtuple("AssignedJob", ["worker", "started_at"])
+
+from sources.job_queue import assign_jobs, assign_jobs_improved
+
+
+class MyTestCase(unittest.TestCase):
+ def test(self):
+ num_workers = 2
+ jobs = [1, 2, 3, 4, 5]
+ result = [AssignedJob(0, 0), AssignedJob(1, 0), AssignedJob(0, 1), AssignedJob(1, 2), AssignedJob(0, 4)]
+ self.assertListEqual(result, assign_jobs_improved(num_workers, jobs))
+
+ def test1(self):
+ num_workers = 4
+ jobs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
+ result = [AssignedJob(0, 0), AssignedJob(1, 0), AssignedJob(2, 0), AssignedJob(3, 0), AssignedJob(0, 1),
+ AssignedJob(1, 1), AssignedJob(2, 1), AssignedJob(3, 1), AssignedJob(0, 2), AssignedJob(1, 2),
+ AssignedJob(2, 2), AssignedJob(3, 2), AssignedJob(0, 3), AssignedJob(1, 3), AssignedJob(2, 3),
+ AssignedJob(3, 3), AssignedJob(0, 4), AssignedJob(1, 4), AssignedJob(2, 4), AssignedJob(3, 4)]
+ self.assertListEqual(result, assign_jobs_improved(num_workers, jobs))
+
+
+if __name__ == '__main__':
+ unittest.main()