add tests
This commit is contained in:
parent
d619623eb3
commit
44eea85a28
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
@ -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
26
tests/test_emulator.py
Normal 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user