def test_updating():
    s1 = State()
    s2 = State()
    t = Transition(s2, 'b', Direction.RIGHT)
    s1.add_transition('a', t)
    tm = TuringMachine("acd", s1, s2, s1)
    assert tm.tape == ['a', 'c', 'd', '_']
    tm._read('a')
    assert tm.tape[0] == 'b'
    assert tm.current_state == s2
def test_tape_never_negative():
    s1 = State()
    s2 = State()
    t = Transition(s2, 'b', Direction.LEFT)
    s1.add_transition('a', t)
    tm = TuringMachine("acd", s1, s2, s1)
    assert tm.tape == ['a', 'c', 'd', '_']
    tm._read('a')
    assert tm.tape[0] == 'b'
    assert tm.current_state == s2
    assert tm.tape_position == 0
def test_example_spec_aab_manually():
    q0, q1, qa, qr = create_example_from_spec()
    tm = TuringMachine('aab', qa, qr, q0)
    assert tm.tape == ['a', 'a', 'b', '_']
    #tm.begin()
    tm._read('a')
    assert tm.tape_position == 1
    assert tm.current_state == q0
    tm._read('a')
    assert tm.tape_position == 2
    assert tm.current_state == q0
    tm._read('b')
    assert tm.tape_position == 3
    assert tm.tape == ['a', 'a', 'b', '_']
    assert tm.current_state == q1
    tm._read('_')
    assert tm.tape_position == 2
    assert tm.tape == ['a', 'a', 'b', 'b', '_']
    assert tm.current_state == qa
    assert tm.accept()