# Universal Turing Machine # from http://www.unidex.com/turing/utm.htm from Xml.Xslt import test_harness source_1 = """ 0123456789 go_right increment stop """ sty_1 = """ Error in source document. The document element of the source element must be 'turing-machine'. Error in source document. The 'turing-machine' element contains an unexpected attribute. The only valid attribute for the 'turing-machine' element is 'version'. Error in source document. The 'turing-machine' element must contain the 'version' attribute, the value of which must be '0.1'. Error in source document. The 'turing-machine' element contains non-whitespace text. Error in source document. The 'turing-machine' element contains an unexpected child element. Only the 'states', 'symbols' and 'transition-function' elements are allowed to be child elements of the 'turing-machine' element. Error in source document. There must be exactly one 'states' element. Error in source document. The 'states' element must not contain any attributes. Error in source document. The 'states' element contains non-whitespace text. Error in source document. The source document must include at least one 'state' element. Error in source document. The 'states' element contains an unexpected child element. Only the 'state' elements are allowed to be child elements of the 'states' element. Error in source document. A 'state' element must not contain any subelements. Error in source document. The 'turing-machine' element must contain exactly one start state. Error in source document. There must be at least one halt state. Error in source document. There is more than one 'state' element that contains the value ' '. Error in source document. Found a 'state' element that contains a null value. Error in source document. A 'state' element contains an unexpected attribute. The valid attributes for the 'state' element are 'start' and 'halt'. Error in source document. The 'halt' attribute in a 'state' element has an invalid value. The valid values are 'yes' and 'no'. Error in source document. The 'start' attribute in a 'state' element has an invalid value. The valid values are 'yes' and 'no'. Error in source document. The value of a 'state' element contains whitespace. Error in source document. The 'turing-machine' element must contain exactly one 'symbols' subelement. Error in source document. The 'symbols' element contains an unexpected attribute. The only valid attribute for the 'symbols' element is 'start-symbol'. Error in source document. The length of the value of the 'blank-symbol' attribute must not be greater than 1. Error in source document. The 'symbols' element must not contain any subelements. Error in source document. The 'symbols' element must contain at least one symbol. Error in source document. The value of the 'symbols' element must not contain the blank symbol. Error in source document. The 'turing-machine' element must contain exactly one 'transition-function' subelement. Error in source document. The 'transition-function' element contains non-whitespace text. Error in source document. The 'turing-machine' element must not contain any attributes. Error in source document. The 'transition-function' element contains an unexpected child element. Only the 'mapping' elements are allowed to be child elements of the 'transition-function' element. Error in source document. A 'from' element must not contain any subelements. Error in source document. A 'to' element must not contain any subelements. Error in source document. There is more than one 'mapping' element whose current symbol is ' ' and whose current state is ' '. Error in source document. A 'mapping' element contains non-whitespace text. Error in source document. A 'mapping' element must not contain any attributes. Error in source document. A 'mapping' element contains an unexpected child element. Only the 'to' and 'from' elements are allowed to be child elements of the 'mapping' element. Error in source document. A 'mapping' element must contain exactly one 'from' sublement. Error in source document. A 'from' element contains non-whitespace text. Error in source document. A 'mapping' element must contain exactly one 'to' sublement. Error in source document. A 'to' element contains non-whitespace text. Error in source document. A 'from' element contains an unexpected attribute. The valid attributes for the 'from' element are 'current-state' and 'current-symbol'. Error in source document. Found a 'from' element that does not contain a 'current-state' attribute. Error in source document. Found a 'from' element that does not contain a 'current-symbol' attribute. Error in source document. Found a 'current-state' attribute that contains a value (' ') that is not a value of a 'state' element. Error in source document. The length of the value of a 'current-symbol' attribute (' ') is not equal to 1. Error in source document. Found a 'current-symbol' attribute that contains a value (' ') that is not a symbol in the 'symbols' element and that is not the blank symbol. Error in source document. A 'to' element contains an unexpected attribute. The valid attributes for the 'to' element are 'next-state', 'next-symbol' and 'movement'. Error in source document. Found a 'to' element that does not contain a 'next-state' attribute. Error in source document. Found a 'to' element that does not contain a 'next-symbol' attribute. Error in source document. Found a 'to' element that does not contain a 'movement' attribute. Error in source document. Found a 'next-state' attribute that contains a value (' ') that is not a value of a 'state' element. Error in source document. The length of the value of a 'next-symbol' attribute (' ') is not equal to 1. Error in source document. Found a 'next-symbol' attribute that contains a value (' ') that is not a symbol in the 'symbols' element and that is not the blank symbol. Error in source document. The 'movement' attribute in a 'to' element has an invalid value. The valid values are 'left', 'right' and 'none'. Error. The value of the global 'tape' parameter must contain at least one symbol. Error. A symbol on the tape (' ') is not one of the symbols defined in the Turing machine. Error. The value of the global 'start-position' parameter is not a number. Error. The value of the global 'start-position' parameter is less then one or greater than the length of the tape. Step number = Tape = Tape head State = Next symbol = Next state = Movement = Error. The transition function is not defined for the current state and current symbol. The Turing machine is crashing. The Turing machine has halted. Final state = Final tape = Tape head ^ Internal error. Bad value for movement. """ expected_1 = """\r Step number = 1\r Tape = 199\r Tape head ^\r State = go_right\r Next symbol = 1\r Next state = go_right\r Movement = right\r \r Step number = 2\r Tape = 199\r Tape head ^\r State = go_right\r Next symbol = 9\r Next state = go_right\r Movement = right\r \r Step number = 3\r Tape = 199\r Tape head ^\r State = go_right\r Next symbol = 9\r Next state = go_right\r Movement = right\r \r Step number = 4\r Tape = 199 \r Tape head ^\r State = go_right\r Next symbol = \r Next state = increment\r Movement = left\r \r Step number = 5\r Tape = 199 \r Tape head ^\r State = increment\r Next symbol = 0\r Next state = increment\r Movement = left\r \r Step number = 6\r Tape = 190 \r Tape head ^\r State = increment\r Next symbol = 0\r Next state = increment\r Movement = left\r \r Step number = 7\r Tape = 100 \r Tape head ^\r State = increment\r Next symbol = 2\r Next state = stop\r Movement = left\r \r The Turing machine has halted.\r Final state = stop\r Final tape = 200 \r Tape head ^\r """ def Test(tester): source = test_harness.FileInfo(string=source_1) sheet = test_harness.FileInfo(string=sty_1) test_harness.XsltTest(tester, source, [sheet], expected_1, topLevelParams={'tape': 199}, title="Universal Turing Machine") return