Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathSJFSchedulingTest.java
More file actions
Latest commit
49 lines (41 loc) · 2.52 KB
/
Copy pathSJFSchedulingTest.java
File metadata and controls
49 lines (41 loc) · 2.52 KB
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
packagecom.thealgorithms.scheduling;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
importcom.thealgorithms.devutils.entities.ProcessDetails;
importjava.util.Collections;
importjava.util.List;
importjava.util.stream.Stream;
importorg.junit.jupiter.api.DisplayName;
importorg.junit.jupiter.api.Test;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
classSJFSchedulingTest {
privatestaticStream<Arguments> schedulingTestData() {
returnStream.of(Arguments.of(List.of(newProcessDetails("1", 0, 6), newProcessDetails("2", 1, 2)), List.of("1", "2")),
Arguments.of(List.of(newProcessDetails("1", 0, 6), newProcessDetails("2", 1, 2), newProcessDetails("3", 4, 3), newProcessDetails("4", 3, 1), newProcessDetails("5", 6, 4), newProcessDetails("6", 5, 5)), List.of("1", "4", "2", "3", "5", "6")),
Arguments.of(List.of(newProcessDetails("1", 0, 3), newProcessDetails("2", 1, 2), newProcessDetails("3", 2, 1)), List.of("1", "3", "2")), Arguments.of(List.of(newProcessDetails("1", 0, 3), newProcessDetails("2", 5, 2), newProcessDetails("3", 9, 1)), List.of("1", "2", "3")),
Arguments.of(Collections.emptyList(), List.of()));
}
@ParameterizedTest(name = "Test SJF schedule: {index}")
@MethodSource("schedulingTestData")
voidtestSJFScheduling(List<ProcessDetails> inputProcesses, List<String> expectedSchedule) {
SJFSchedulingscheduler = newSJFScheduling(inputProcesses);
scheduler.scheduleProcesses();
assertEquals(expectedSchedule, scheduler.getSchedule());
}
@Test
@DisplayName("Test sorting by arrival order")
voidtestProcessArrivalOrderIsSorted() {
List<ProcessDetails> processes = List.of(newProcessDetails("1", 0, 6), newProcessDetails("2", 1, 2), newProcessDetails("4", 3, 1), newProcessDetails("3", 4, 3), newProcessDetails("6", 5, 5), newProcessDetails("5", 6, 4));
SJFSchedulingscheduler = newSJFScheduling(processes);
List<String> actualOrder = scheduler.getProcesses().stream().map(ProcessDetails::getProcessId).toList();
assertEquals(List.of("1", "2", "4", "3", "6", "5"), actualOrder);
}
@Test
voidtestSchedulingEmptyList() {
SJFSchedulingscheduler = newSJFScheduling(Collections.emptyList());
scheduler.scheduleProcesses();
assertTrue(scheduler.getSchedule().isEmpty());
}
}