def test_init_happy_path(): h = HanoiState(4, 0, 2) assert h.numberOfDiscs == 4 assert h.source == 0 assert h.target == 2 assert h.numberOfMoves == 0 assert h.tower[0] == 0b1111 assert h.tower[1] == 0b0000 assert h.tower[2] == 0b0000
def test_to_json(): h = HanoiState(4, 0, 2) j = json.loads(h.to_json()) assert isinstance(j['sessionId'], int) assert j['numberOfDiscs'] == 4 assert j['fromTower'] == 0 assert j['toTower'] == 2 assert j['numberOfMoves'] == 0 assert j['towers'] == [15, 0, 0]
def __init__(self, numberOfDiscs, source, target): '''Initialize a Hanoi object''' self._state = HanoiState(numberOfDiscs, source, target) self._lock = threading.Lock()
def test_init_source_eq_target(): with pytest.raises(ValueError, match=r"source may not equal target"): h = HanoiState(1, 0, 0)
def test_init_target_gt2(): with pytest.raises(ValueError, match=r"target 3 is invalid"): h = HanoiState(1, 0, 3)
def test_init_target_n1(): with pytest.raises(ValueError, match=r"target -1 is invalid"): h = HanoiState(1, 0, -1)
def test_init_source_gt2(): with pytest.raises(ValueError, match=r"source 3 is invalid"): h = HanoiState(1, 3, 2)
def test_init_source_n1(): with pytest.raises(ValueError, match=r"source -1 is invalid"): h = HanoiState(1, -1, 2)
def test_init_numberOfDiscs_gt64(): with pytest.raises(ValueError, match=r"numberOfDiscs 65 is invalid"): h = HanoiState(65, 0, 2)
def test_init_numberOfDiscs_n1(): with pytest.raises(ValueError, match=r"numberOfDiscs -1 is invalid"): h = HanoiState(-1, 0, 2)