-
Notifications
You must be signed in to change notification settings - Fork 1
/
standard_test.go
94 lines (85 loc) · 3.11 KB
/
standard_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package turing
import (
"testing"
)
func TestStandardMachineExample1(t *testing.T) {
st := NewStandardTable(MachineInput{
MConfigurations: []MConfiguration{
{"b", []string{" "}, []string{"P0", "R"}, "c"},
{"c", []string{" "}, []string{"R"}, "e"},
{"e", []string{" "}, []string{"P1", "R"}, "k"},
{"k", []string{" "}, []string{"R"}, "b"},
},
PossibleSymbols: []string{"0", "1"},
})
m := NewMachine(st.MachineInput)
m.MoveN(100)
checkTape(t, st.SymbolMap.TranslateTape(m.Tape()), "0 1 0 1 0 1 0 1 0 1 0 1")
checkStandardDescription(t, st.StandardDescription, ";DADDCRDAA;DAADDRDAAA;DAAADDCCRDAAAA;DAAAADDRDA")
checkDescriptionNumber(t, st.DescriptionNumber, "73133253117311335311173111332253111173111133531")
}
func TestStandardMachineExample1Short(t *testing.T) {
st := NewStandardTable(MachineInput{
MConfigurations: []MConfiguration{
{"b", []string{" "}, []string{"P0"}, "b"},
{"b", []string{"0"}, []string{"R", "R", "P1"}, "b"},
{"b", []string{"1"}, []string{"R", "R", "P0"}, "b"},
},
PossibleSymbols: []string{"0", "1"},
})
m := NewMachine(st.MachineInput)
m.MoveN(100)
checkTape(t, st.SymbolMap.TranslateTape(m.Tape()), "0 1 0 1 0 1 0 1 0 1 0 1")
// No StandardDescription or DescriptionNumner given
}
func TestStandardMachineExample2(t *testing.T) {
st := NewStandardTable(MachineInput{
MConfigurations: []MConfiguration{
{"b", []string{"*", " "}, []string{"Pe", "R", "Pe", "R", "P0", "R", "R", "P0", "L", "L"}, "o"},
{"o", []string{"1"}, []string{"R", "Px", "L", "L", "L"}, "o"},
{"o", []string{"0"}, []string{}, "q"},
{"q", []string{"0", "1"}, []string{"R", "R"}, "q"},
{"q", []string{" "}, []string{"P1", "L"}, "p"},
{"p", []string{"x"}, []string{"E", "R"}, "q"},
{"p", []string{"e"}, []string{"R"}, "f"},
{"p", []string{" "}, []string{"L", "L"}, "p"},
{"f", []string{"*"}, []string{"R", "R"}, "f"},
{"f", []string{" "}, []string{"P0", "L", "L"}, "o"},
},
PossibleSymbols: []string{"0", "1", "e", "x"},
})
m := NewMachine(st.MachineInput)
m.MoveN(1000)
checkTape(t, st.SymbolMap.TranslateTape(m.Tape()), "ee0 0 1 0 1 1 0 1 1 1 0 1 1 1 1")
// No StandardDescription or DescriptionNumner given
}
func TestNewMachineFromDescriptionNumber(t *testing.T) {
st := NewStandardTable(MachineInput{
MConfigurations: []MConfiguration{
{"b", []string{" "}, []string{"P0", "R"}, "c"},
{"c", []string{" "}, []string{"R"}, "e"},
{"e", []string{" "}, []string{"P1", "R"}, "k"},
{"k", []string{" "}, []string{"R"}, "b"},
},
PossibleSymbols: []string{"0", "1"},
})
m := NewMachine(st.MachineInput)
m.MoveN(100)
newMachineInput, err := NewMachineFromDescriptionNumber(st.DescriptionNumber)
if err != nil {
t.Error(err)
}
newM := NewMachine(newMachineInput)
newM.MoveN(100)
checkTape(t, m.TapeString(), newM.TapeString())
}
func checkStandardDescription(t *testing.T, actual StandardDescription, expected string) {
if string(actual) != expected {
t.Errorf("got %s, want %s", actual, expected)
}
}
func checkDescriptionNumber(t *testing.T, actual DescriptionNumber, expected string) {
if string(actual) != expected {
t.Errorf("got %s, want %s", actual, expected)
}
}