# Copyright (c) 2009 Tim Freeman # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # (This is the standard MIT License, copied from # http://www.opensource.org/licenses/mit-license.php on 24 Apr 2007.) from turing_tape import turing_tape import sys from constants import left, right, end, done, truncate import machine from compile import turing_program, turing_compile from animate import draw_action, show_octal, draw_tape import animate import test_util from test_util import assert_equals assert draw_tape(8, 0x5a, 3) == ' 0 1 0 1>1<0 1 0 ' assert draw_tape(8, 0x5a, 0) == ' 0 1 0 1 1 0 1>0<' assert draw_tape(8, 0x5a, 8) == '> <0 1 0 1 1 0 1 0 ' assert show_octal(3) == "003" assert draw_action(055, 3, state_to_name = show_octal) == "w1r 005" empty_as = turing_program("trunc", trunc = {(0,1,end):(1, left, "done")}, done = done) c = turing_compile(empty_as, pretty_octal = True) def exercise(): machine.turing(c.program, turing_tape(length=5,bits=0), 50, animate=animate.default_animation) v = test_util.with_output_to_string(exercise) assert_equals(v["output"].strip(), """ 0 0 0 0>0< state 000 0>w1l 001 1>w1l 001 end>w1l 001 0 0 0>0<1 state 001 0>dnl 001 1>dnl 001 end>dnl 001 0 0 0>0<1 """.strip()) assert v["exception"] is None