Пример #1
0
def test_stack_to_string():
    stk = Stack()
    assert str(stk) == "[ ]"
    stk.push(2)
    assert str(stk) == "[2]"
    stk.push(3)
    assert str(stk) == "[3, 2]"
Пример #2
0
def test_stack_push_pop():
    stk = Stack()
    stk.push(2)
    stk.push(3)
    assert stk.peek() == 3
    assert stk.pop() == 3
    assert stk.peek() == 2
    assert stk.pop() == 2
Пример #3
0
def test_executor_g():
    lines = [['>', 'v'], ['<', '^']]
    fld = Field(2, 2, lines)
    stk = Stack()
    crt = Caret(stk, fld)
    stk.push(1)
    stk.push(0)
    exec_g(crt)
    assert stk.peek() == ord('v')
Пример #4
0
def test_stack_swap():
    stk = Stack()
    stk.push(2)
    stk.push(3)
    stk.swap()
    assert stk.peek() == 2
    assert stk.pop() == 2
    assert stk.peek() == 3
    assert stk.pop() == 3
Пример #5
0
def test_executor_p():
    lines = [['>', 'v'], ['<', '^']]
    fld = Field(2, 2, lines)
    stk = Stack()
    crt = Caret(stk, fld)
    stk.push(ord('@'))
    stk.push(1)
    stk.push(0)
    exec_p(crt)
    assert fld.get_symbol_at(1, 0) == '@'
Пример #6
0
def test_vertical_if():
    lines = [['|']]
    fld = Field(1, 1, lines)
    stk = Stack()
    crt = Caret(stk, fld)

    stk.push(174)
    crt.read_instruction(fld)
    crt.execute_instruction()
    assert crt.direction == Up
    stk.push(0)
    crt.read_instruction(fld)
    crt.execute_instruction()
    assert crt.direction == Down
Пример #7
0
def test_horizontal_if():
    lines = [['_']]
    fld = Field(1, 1, lines)
    stk = Stack()
    crt = Caret(stk, fld)

    stk.push(174)
    crt.read_instruction(fld)
    crt.execute_instruction()
    assert crt.direction == Left
    stk.push(0)
    crt.read_instruction(fld)
    crt.execute_instruction()
    assert crt.direction == Right