diff options
author | Haidong Ji | 2019-02-21 19:54:08 -0600 |
---|---|---|
committer | Haidong Ji | 2019-02-21 19:54:08 -0600 |
commit | 3a6cbab3d53e5b04a6ea10df7854e4f3bce4f3a3 (patch) | |
tree | c02c679cb8241e79b5bf11975892df57c342ebb4 /src/test | |
parent | cbb64e8ab441750535ced849154f16df4add8d78 (diff) |
Parallel processing job queue done!
Fun exercise. Facing a difficult problem, always take small/concrete and
concrete steps, and you'll get there! Writing down pseudo code helped,
along with creating a subclass implementing the Comparable interface.
Good thing that I've done that before and have example to follow.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/JobQueueTest.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/JobQueueTest.java b/src/test/JobQueueTest.java new file mode 100644 index 0000000..e0e8a29 --- /dev/null +++ b/src/test/JobQueueTest.java @@ -0,0 +1,33 @@ +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class JobQueueTest { + @Test + void test() { + int numWorkers = 2; + int[] jobs = {1, 2, 3, 4, 5}; + JobQueue jobQueue = new JobQueue(); + jobQueue.numWorkers = numWorkers; + jobQueue.jobs = jobs; + jobQueue.assignJobsImproved(); + assertEquals(5, jobQueue.assignedWorker.length); + assertEquals(5, jobQueue.startTime.length); + assertArrayEquals(new int[]{0, 1, 0, 1, 0}, jobQueue.assignedWorker); + assertArrayEquals(new long[]{0, 0, 1, 2, 4}, jobQueue.startTime); + } + + @Test + void test1() { + int numWorkers = 4; + int[] jobs = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + JobQueue jobQueue = new JobQueue(); + jobQueue.numWorkers = numWorkers; + jobQueue.jobs = jobs; + jobQueue.assignJobsImproved(); + assertEquals(20, jobQueue.assignedWorker.length); + assertEquals(20, jobQueue.startTime.length); + assertArrayEquals(new int[]{0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3}, jobQueue.assignedWorker); + assertArrayEquals(new long[]{0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4}, jobQueue.startTime); + } +}
\ No newline at end of file |