tests.html


001| '''Tests for UTM: TuringTape and TuringMachine.'''
002| ####################################################################################################
003| from sys import argv
004| from os import path
005| from files import EOL, textfile, linefile
006| from goodies import KWARG, typename
007| from utm import TuringTape, TuringMachine, Programs
008| ####################################################################################################
009| BasePath = r'C:\CJS\prj\Python\app\sims\utm'
010| 
011| ##================================================================================================##
012| def dump_tape_properties (tt):
013|     print('[%s]\n%s\n' % (str(tt), repr(tt)))
014|     print('length: %d' % len(tt))
015|     print('#cells: %d' % len(tt.keys))
016|     print('left : %s' % tt.left)
017|     print('curr : %s' % tt.curr)
018|     print('right : %s' % tt.right)
019|     print()
020|     print('keys : %s' % tt.keys)
021|     print('values: %s' % tt.values)
022|     print('counts: %s' % tt.counts)
023|     print()
024|     print('items : %s' % tt.items)
025|     print()
026|     print('list : %s' % list(tt))
027|     print()
028| 
029| ##================================================================================================##
030| def test_tape_1 ():
031|     tt = TuringTape()
032|     dump_tape_properties(tt)
033|     return tt
034| 
035| ##================================================================================================##
036| def test_tape_2 ():
037|     tt = TuringTape(blank=9, head=+2, tape=[9,8,7,6,5,4], tx=-12)
038|     dump_tape_properties(tt)
039|     return tt
040| 
041| ##================================================================================================##
042| def test_tape_3 ():
043|     tt = TuringTape(head=+10)
044|     dump_tape_properties(tt)
045|     tt(3,-1)
046|     tt(7,-1)
047|     tt(7,-1)
048|     tt(7,-1)
049|     tt(4,-1)
050|     tt(7,-1)
051|     tt(2,-1)
052|     tt(1,-1)
053|     tt(5,-1)
054|     tt(6,-1)
055|     tt(1,0)
056|     dump_tape_properties(tt)
057|     return tt
058| 
059| 
060| ##================================================================================================##
061| def main (*args):
062|     #tt1 = test_tape_1()
063|     #tt2 = test_tape_2()
064|     #tt3 = test_tape_3()
065| 
066|     pgm = Programs['BB']
067|     tm = TuringMachine(pgm)
068|     tm.run()
069|     tm.dump()
070| 
071|     return tm
072| 
073| ####################################################################################################
074| if __name__ == "__main__":
075|     print('autorun: %s' % argv[0])
076|     rv = main(*argv[1:])
077|     print(rv)
078| ####################################################################################################
079| '''eof'''
080|