From dfe7f50ca30844c8a256802a90dd743733bc242e Mon Sep 17 00:00:00 2001 From: Ankush Singh Gandhi Date: Tue, 9 Apr 2024 19:51:09 +0530 Subject: [PATCH] Create test_rr.py --- tests/test_rr.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/test_rr.py diff --git a/tests/test_rr.py b/tests/test_rr.py new file mode 100644 index 0000000..286a7d5 --- /dev/null +++ b/tests/test_rr.py @@ -0,0 +1,54 @@ +import pytest +from src.sjf_scheduler import SJFScheduler +from src.process import Process + +def test_rr_scheduler(): + # Create some sample processes + processes = [ + Process("P1", arrival_time=0, burst_time=5, priority=1), + Process("P2", arrival_time=1, burst_time=3, priority=2), + Process("P3", arrival_time=2, burst_time=7, priority=3) + ] + + # Initialize the RR scheduler + scheduler = RRScheduler() + + # Schedule the processes + scheduling_output = scheduler.schedule(processes) + + # Verify the scheduling output + expected_output = """Process ID\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time\n\ +P1\t\t0\t\t5\t\t5\t\t10\n\ +P2\t\t1\t\t3\t\t4\t\t7\n\ +P3\t\t2\t\t7\t\t6\t\t13\n\ +\n\ +Average Waiting Time: 5.0\n\ +Average Turnaround Time: 10.0\n\ +""" + assert scheduling_output.strip() == expected_output.strip() + +def test_rr_scheduler_different_quantum(): + # Create some sample processes with different time quantum + processes = [ + Process("P1", arrival_time=0, burst_time=5, priority=1), + Process("P2", arrival_time=1, burst_time=3, priority=2), + Process("P3", arrival_time=2, burst_time=7, priority=3) + ] + + # Initialize the RR scheduler with a different time quantum + scheduler = RRScheduler() + scheduler.time_quantum = 3 + + # Schedule the processes + scheduling_output = scheduler.schedule(processes) + + # Verify the scheduling output + expected_output = """Process ID\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time\n\ +P1\t\t0\t\t5\t\t5\t\t10\n\ +P2\t\t1\t\t3\t\t4\t\t7\n\ +P3\t\t2\t\t7\t\t6\t\t13\n\ +\n\ +Average Waiting Time: 5.0\n\ +Average Turnaround Time: 10.0\n\ +""" + assert scheduling_output.strip() == expected_output.strip()