From c644f52839fe320bf4c8c21661ae8534fd60b37d Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Tue, 24 Sep 2024 07:17:41 +0200 Subject: Refactor Card out of parser.py, implement brutal scheduler constructor --- src/scheduler_brutal_unittest.py | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/scheduler_brutal_unittest.py (limited to 'src/scheduler_brutal_unittest.py') diff --git a/src/scheduler_brutal_unittest.py b/src/scheduler_brutal_unittest.py new file mode 100644 index 0000000..98de2f1 --- /dev/null +++ b/src/scheduler_brutal_unittest.py @@ -0,0 +1,68 @@ +import pytest +import scheduler_brutal +from scheduler_brutal import SchedulerBrutal as UUT +from card import Card + +# Force HISTORY_DEPTH to simplify testing +scheduler_brutal.HISTORY_DEPTH = 3 + +#-------------------------------------------------------------------------- +# +#-------------------------------------------------------------------------- + +#-------------------------------------------------------------------------- +# +#-------------------------------------------------------------------------- + +#-------------------------------------------------------------------------- +# +#-------------------------------------------------------------------------- + +#-------------------------------------------------------------------------- +# +#-------------------------------------------------------------------------- + +#-------------------------------------------------------------------------- +# +#-------------------------------------------------------------------------- + +#-------------------------------------------------------------------------- +# +#-------------------------------------------------------------------------- + +#-------------------------------------------------------------------------- +# State corrections +#-------------------------------------------------------------------------- +def test_stateWhenCardsChanged(): + cards = {"0": Card("f", "b"), "1": Card("a", "b")} + + initial_state = {"0": [1, 0, 1], "-1": [0, 0, 0]} + expected_state = {"0": [1, 0, 1], "1": [None, None, None]} + + uut = UUT(cards, initial_state) + + assert uut.getState() == expected_state + +def test_stateWhenHistoryDepthIncreased(): + scheduler_brutal.HISTORY_DEPTH = 5 + + cards = {"0": Card("f", "b"), "1": Card("a", "b"), "2": Card("new", "new")} + + initial_state = {"0": [1, 0, 1], "1": [0, 0, 0]} + expected_state = {"0": [None, None, 1, 0, 1], "1": [None, None, 0, 0, 0], "2": [None] * 5} + + uut = UUT(cards, initial_state) + + assert uut.getState() == expected_state + +def test_stateWhenHistoryDepthDecreased(): + scheduler_brutal.HISTORY_DEPTH = 1 + + cards = {"0": Card("f", "b"), "1": Card("a", "b"), "2": Card("new", "new")} + + initial_state = {"0": [1, 0, 0], "1": [0, 0, 1]} + expected_state = {"0": [0], "1": [1], "2": [None]} + + uut = UUT(cards, initial_state) + + assert uut.getState() == expected_state -- cgit v1.2.3