-
Notifications
You must be signed in to change notification settings - Fork 2
/
tm_test.go
48 lines (37 loc) · 962 Bytes
/
tm_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
package tm_test
import (
"fmt"
"testing"
. "github.com/kkdai/tm"
)
// Simple TM
func TestBasicTM(t *testing.T) {
nTM := NewTM()
nTM.InputState("0", false)
nTM.InputState("1", false)
nTM.InputState("2", true)
nTM.InputConfig("0", "1", "1", "1", MoveRight)
nTM.InputConfig("1", "1", "1", "2", MoveRight)
nTM.InputTape("1", "1")
if nTM.Step() {
t.Errorf("TM: Should not stop")
}
if !nTM.Step() {
t.Errorf("TM: Should be accept")
}
}
// A TM to rewrite all tape 0 to 1
func TestModifyTM(t *testing.T) {
nTM := NewTM()
nTM.InputState("0", false)
nTM.InputState("1", true)
nTM.InputConfig("0", "1", "1", "1", MoveRight)
nTM.InputConfig("0", "0", "1", "0", MoveLeft)
nTM.InputConfig("1", "0", "1", "0", MoveLeft)
nTM.InputConfig("1", "1", "1", "1", MoveRight)
nTM.InputTape("0", "0", "1", "1", "0", "0", "0")
if !nTM.Run() {
t.Errorf("TM: Cannot reach to end")
}
fmt.Println("New Tape:=", nTM.ExportTape(), nTM.CurrentState)
}