From 44eea85a282bda81b174bc5099efd0bfbd43525f Mon Sep 17 00:00:00 2001 From: Maxim Slipenko <36362599+Maks1mS@users.noreply.github.com> Date: Fri, 17 Sep 2021 21:56:19 +0300 Subject: [PATCH] add tests --- .vscode/settings.json | 7 ++++++- tests/test_emulator.py | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/test_emulator.py diff --git a/.vscode/settings.json b/.vscode/settings.json index f2d90cb..882c8c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,8 @@ { - "python.linting.enabled": true + "python.linting.enabled": true, + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true, } \ No newline at end of file diff --git a/tests/test_emulator.py b/tests/test_emulator.py new file mode 100644 index 0000000..18010e4 --- /dev/null +++ b/tests/test_emulator.py @@ -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 +