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 update #-------------------------------------------------------------------------- def test_stateUpdate(): cards = {0: Card("f", "b"), 1: Card("a", "b"), 2: Card("c", "d")} state = {0: [1, 0, 1], 1: [1, 0, 0], 2: [0, 0, 1]} uut = UUT(cards, state) # Unknown IDs in the result are silently ignored result = {0: 1, 1: 0, 3: 0} expected_state = {0: [0, 1, 1], 1: [0, 0, 0], 2: [0, 1, None]} uut.update(result) assert uut.getState() == expected_state #-------------------------------------------------------------------------- # 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