summaryrefslogtreecommitdiff
path: root/src/test/JobQueueTest.java
blob: e0e8a2946987ade2fb0e4b65613445cbaac97078 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
    }
}