add tests

This commit is contained in:
Maxim Slipenko 2021-09-17 21:56:19 +03:00
parent d619623eb3
commit 44eea85a28
2 changed files with 32 additions and 1 deletions

View File

@ -1,3 +1,8 @@
{ {
"python.linting.enabled": true "python.linting.enabled": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
} }

26
tests/test_emulator.py Normal file
View File

@ -0,0 +1,26 @@
from turinglab.emulator import Emulator
from turinglab.output import to_docx
def test_emulator():
blank_symbol = '_'
instructions = {
'0': [['1', '>', 0], ['0', '<', 1]],
'1': [['0', '>', 0], ['1', '<', 1]],
blank_symbol: [[blank_symbol, '<', 1], [blank_symbol, '>', -1]]
}
input_string = '010'
tm = Emulator(instructions, input_string, blank_symbol)
while not tm.stopped:
tm.step()
head, _, tape = tm.info()
output_string = "".join(tape.values()).strip(blank_symbol)
assert output_string == '101'
assert head == 0