mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
Add Preemptive Priority Scheduling Algorithm (#4323)
This commit is contained in:

committed by
GitHub

parent
af80c8005d
commit
4bcddd323c
@ -0,0 +1,32 @@
|
||||
package com.thealgorithms.scheduling;
|
||||
|
||||
/**
|
||||
* Test Cases of Preemptive Priority Scheduling Algorithm
|
||||
* @author [Bama Charan Chhandogi](https://www.github.com/BamaCharanChhandogi)
|
||||
*/
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PreemptivePrioritySchedulingTest {
|
||||
|
||||
@Test
|
||||
void testPreemptivePriorityScheduling() {
|
||||
// Arrange
|
||||
List<Process> processes = new ArrayList<>();
|
||||
processes.add(new Process("P1", 0, 5, 10));
|
||||
processes.add(new Process("P2", 1, 4, 20));
|
||||
processes.add(new Process("P3", 2, 2, 30));
|
||||
processes.add(new Process("P4", 4, 1, 40));
|
||||
|
||||
List<String> expectedGanttChart = Arrays.asList("P1", "P2", "P3", "P3", "P4", "P2", "P2", "P2", "P1", "P1", "P1", "P1");
|
||||
|
||||
// Act
|
||||
List<String> actualGanttChart = PreemptivePriorityScheduling.preemptivePriorityScheduling(processes);
|
||||
|
||||
// Assert
|
||||
assertEquals(expectedGanttChart, actualGanttChart);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user