示例#1
0
def test_move_locked():
    h = Hanoi(4, 0, 2)
    h._lock.acquire()
    with pytest.raises(TimeoutError):
        h.move(0, 2, 0)
示例#2
0
def test_move_source_n1():
    h = Hanoi(4, 0, 2)
    with pytest.raises(ValueError, match=r'source 3 is invalid'):
        h.move(3, 2)
示例#3
0
def test_move_happy_path():
    h = Hanoi(4, 0, 2)
    assert h._state.tower[0] == 0b1111
    h.move(0, 1)
    # smallest disc / least-significant bit is moved
    assert h._state.tower[0] == 0b1110
    assert h._state.tower[1] == 0b0001
    h.move(0, 2)
    h.move(1, 2)
    h.move(0, 1)
    h.move(2, 0)
    h.move(2, 1)
    h.move(0, 1)
    h.move(0, 2)
    h.move(1, 2)
    h.move(1, 0)
    h.move(2, 0)
    h.move(1, 2)
    h.move(0, 1)
    h.move(0, 2)
    h.move(1, 2)
    assert h._state.tower[2] == 0b1111
示例#4
0
def test_move_bigger_disc():
    h = Hanoi(4, 0, 2)
    h.move(0, 2)
    with pytest.raises(ValueError,
                       match=r'cannot put disc 2 on top of disc 1'):
        h.move(0, 2)
示例#5
0
def test_move_empty_source():
    h = Hanoi(4, 0, 2)
    with pytest.raises(ValueError, match=r'source 1 is empty'):
        h.move(1, 0)
示例#6
0
def test_move_source_eq_target():
    h = Hanoi(4, 0, 2)
    with pytest.raises(ValueError, match=r'source may not equal target'):
        h.move(0, 0)
示例#7
0
def test_move_target_n1():
    h = Hanoi(4, 0, 2)
    with pytest.raises(ValueError, match=r'target 3 is invalid'):
        h.move(0, 3)