-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathHighestResponseRatioNextSchedulingTest.java
112 lines (85 loc) · 4.76 KB
/
HighestResponseRatioNextSchedulingTest.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.thealgorithms.scheduling;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.jupiter.api.Test;
public class HighestResponseRatioNextSchedulingTest {
@Test
public void testCalculateTurnAroundTime() {
String[] processNames = {"A", "B", "C"};
int[] arrivalTimes = {0, 2, 4};
int[] burstTimes = {3, 1, 2};
int noOfProcesses = 3;
int[] expectedTurnAroundTimes = {3, 2, 2};
int[] actualTurnAroundTimes = HighestResponseRatioNextScheduling.calculateTurnAroundTime(processNames, arrivalTimes, burstTimes, noOfProcesses);
assertArrayEquals(expectedTurnAroundTimes, actualTurnAroundTimes, "Turn Around Times do not match");
}
@Test
public void testCalculateWaitingTime() {
int[] turnAroundTimes = {3, 1, 5};
int[] burstTimes = {3, 1, 2};
int[] expectedWaitingTimes = {0, 0, 3};
int[] actualWaitingTimes = HighestResponseRatioNextScheduling.calculateWaitingTime(turnAroundTimes, burstTimes);
assertArrayEquals(expectedWaitingTimes, actualWaitingTimes, "Waiting Times do not match");
}
@Test
public void testCompleteSchedulingScenario() {
String[] processNames = {"A", "B", "C"};
int[] arrivalTimes = {0, 1, 2};
int[] burstTimes = {5, 2, 1};
int[] expectedTurnAroundTimes = {5, 7, 4};
int[] turnAroundTimes = HighestResponseRatioNextScheduling.calculateTurnAroundTime(processNames, arrivalTimes, burstTimes, processNames.length);
assertArrayEquals(expectedTurnAroundTimes, turnAroundTimes, "Turn Around Times do not match");
int[] expectedWaitingTimes = {0, 5, 3};
int[] waitingTimes = HighestResponseRatioNextScheduling.calculateWaitingTime(turnAroundTimes, burstTimes);
assertArrayEquals(expectedWaitingTimes, waitingTimes, "Waiting Times do not match");
}
@Test
public void testZeroProcesses() {
String[] processNames = {};
int[] arrivalTimes = {};
int[] burstTimes = {};
int noOfProcesses = 0;
int[] expectedTurnAroundTimes = {};
int[] actualTurnAroundTimes = HighestResponseRatioNextScheduling.calculateTurnAroundTime(processNames, arrivalTimes, burstTimes, noOfProcesses);
assertArrayEquals(expectedTurnAroundTimes, actualTurnAroundTimes, "Turn Around Times for zero processes should be an empty array");
}
@Test
public void testAllProcessesArriveAtSameTime() {
String[] processNames = {"A", "B", "C", "D"};
int[] arrivalTimes = {0, 0, 0, 0};
int[] burstTimes = {4, 3, 1, 2};
int noOfProcesses = 4;
int[] expectedTurnAroundTimes = {4, 10, 5, 7};
int[] actualTurnAroundTimes = HighestResponseRatioNextScheduling.calculateTurnAroundTime(processNames, arrivalTimes, burstTimes, noOfProcesses);
assertArrayEquals(expectedTurnAroundTimes, actualTurnAroundTimes, "Turn Around Times for processes arriving at the same time do not match");
}
@Test
public void testProcessesWithZeroBurstTime() {
String[] processNames = {"A", "B", "C"};
int[] arrivalTimes = {0, 1, 2};
int[] burstTimes = {3, 0, 2};
int noOfProcesses = 3;
int[] expectedTurnAroundTimes = {3, 2, 3};
int[] actualTurnAroundTimes = HighestResponseRatioNextScheduling.calculateTurnAroundTime(processNames, arrivalTimes, burstTimes, noOfProcesses);
assertArrayEquals(expectedTurnAroundTimes, actualTurnAroundTimes, "Turn Around Times for processes with zero burst time do not match");
}
@Test
public void testProcessesWithLargeGapsBetweenArrivals() {
String[] processNames = {"A", "B", "C"};
int[] arrivalTimes = {0, 100, 200};
int[] burstTimes = {10, 10, 10};
int noOfProcesses = 3;
int[] expectedTurnAroundTimes = {10, 10, 10};
int[] actualTurnAroundTimes = HighestResponseRatioNextScheduling.calculateTurnAroundTime(processNames, arrivalTimes, burstTimes, noOfProcesses);
assertArrayEquals(expectedTurnAroundTimes, actualTurnAroundTimes, "Turn Around Times for processes with large gaps between arrivals do not match");
}
@Test
public void testProcessesWithVeryLargeBurstTimes() {
String[] processNames = {"A", "B"};
int[] arrivalTimes = {0, 1};
int[] burstTimes = {Integer.MAX_VALUE / 2, Integer.MAX_VALUE / 2};
int noOfProcesses = 2;
int[] expectedTurnAroundTimes = {Integer.MAX_VALUE / 2, Integer.MAX_VALUE - 2};
int[] actualTurnAroundTimes = HighestResponseRatioNextScheduling.calculateTurnAroundTime(processNames, arrivalTimes, burstTimes, noOfProcesses);
assertArrayEquals(expectedTurnAroundTimes, actualTurnAroundTimes, "Turn Around Times for processes with very large burst times do not match");
}
}