# 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 bits import test_util import machine from compile import turing_program, turing_compile from constants import left, right, end, done, truncate # Verify that we get None out of the turing interpreter when we should. fail_machine_as = turing_program("start", start={(0,1,end):(truncate, right, "start")}) compiled = turing_compile(fail_machine_as).program test_util.expect_exception(lambda: machine.turing(compiled, (0,0), 10)) assert "Wrong type for tape argument" in \ str(test_util.expect_exception(lambda:machine.turing(machine=17, tape=False, time=34))) longer_machine_as = turing_program("start", start={(0,1,end):(1, left, "second")}, second={(0,1,end):(1, left, done)}, done=done) longer_compiled = turing_compile(longer_machine_as).program assert machine.turing(machine=longer_compiled, tape=turing_tape(length=1, bits=1), time=5) == \ turing_tape(length=2, bits=3) assert "Out of time" in str(test_util.expect_exception( lambda:machine.turing(machine=longer_compiled, tape=turing_tape(length=2, bits=3), time=0))) happened = False try: raise machine.Machine_failure() except bits.Doesnt_match: happened = True assert happened