-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabbreviated_test.go
567 lines (501 loc) · 22.6 KB
/
abbreviated_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
package turing
import (
"reflect"
"testing"
)
var (
// `ph`. Prints the provided character, and halts.
printAndHalt = MConfiguration{"ph(b)", []string{"*", " "}, []string{"Pb"}, "halt"}
// `prh`. Prints the provided character to the right, and halts.
printToRightAndHalt = MConfiguration{"prh(b)", []string{"*", " "}, []string{"R", "Pb"}, "halt"}
)
func TestParseMFunctionRecursiveFirst(t *testing.T) {
checkParseMFunction(t, "f(x(y, z), a, b)", "f", []string{"x(y, z)", "a", "b"})
}
func TestParseMFunctionRecursiveMiddle(t *testing.T) {
checkParseMFunction(t, "f(a, x(y, z), b)", "f", []string{"a", "x(y, z)", "b"})
}
func TestParseMFunctionRecursiveLast(t *testing.T) {
checkParseMFunction(t, "f(a, b, x(y, z))", "f", []string{"a", "b", "x(y, z)"})
}
func TestParseMFunctionRecursiveTwice(t *testing.T) {
checkParseMFunction(t, "f(x(y, z), x(y, z), b)", "f", []string{"x(y, z)", "x(y, z)", "b"})
}
func TestParseMFunctionBlank(t *testing.T) {
checkParseMFunction(t, "f(x, )", "f", []string{"x", " "})
}
func TestParseMFunctionNoFunction(t *testing.T) {
checkParseMFunction(t, "f", "f", []string{})
}
func checkParseMFunction(t *testing.T, mFunction string, expectedName string, expectedParams []string) {
actualName, actualParams := parseMFunction(mFunction)
if actualName != expectedName {
t.Errorf("got %s, want %s", actualName, expectedName)
}
if !reflect.DeepEqual(actualParams, expectedParams) {
t.Errorf("got %s, want %s", actualParams, expectedParams)
}
}
func TestFindLeftMost(t *testing.T) {
mConfigurations := []MConfiguration{
// Invokes the findLeftMost MFunction (`f`), printing `x` or `y` depending on if `0` is found
{"b", []string{"*", " "}, []string{"R", "R", "R"}, "f(ph(x), ph(y), 0)"},
}
mConfigurations = append(mConfigurations, printAndHalt)
mConfigurations = append(mConfigurations, findLeftMost...)
possibleSymbols := []string{"e", "x", "y", "0", "1"}
t.Run("FindFirstZero", func(t *testing.T) {
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "1", " ", "1", " ", "0", " ", "0"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee1 1 x 0")
})
t.Run("NoZero", func(t *testing.T) {
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "1", " ", "1"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee1 1 y")
})
}
func TestErase(t *testing.T) {
// Invokes the erase MFunction (`e`), printing `x` or `y` depending on if `z` is found and erased
eraseOnceTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "e(ph(x), ph(y), z)"}
// Invokes the erase MFunction (`e`), printing `x` or `y` depending on if all `z` symbols are found and erased
eraseAllTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "e(ph(x), z)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, printAndHalt)
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, erase...)
possibleSymbols := []string{"e", "0", "z", "x", "y"}
t.Run("EraseX", func(t *testing.T) {
mConfigurations := append(mConfigurations, eraseOnceTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", "z", "0", "z"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee0x0z")
})
t.Run("EraseXDoesNotExist", func(t *testing.T) {
mConfigurations := append(mConfigurations, eraseOnceTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee y")
})
t.Run("EraseAll", func(t *testing.T) {
mConfigurations := append(mConfigurations, eraseAllTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "", "z", " ", "z"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(30)
checkTape(t, m.TapeString(), "ee x")
})
}
func TestPrintAtTheEnd(t *testing.T) {
// Invokes the printAtTheEnd MFunction (`pe`), printing `x` at the end of the sequence
printAtTheEndTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "pe(halt, x)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, printAtTheEnd...)
mConfigurations = append(mConfigurations, printAtTheEndTest)
possibleSymbols := []string{"e", "0", "x"}
t.Run("PrintAtTheEnd", func(t *testing.T) {
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "0"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee0 0 x")
})
}
func TestFindLeft(t *testing.T) {
// Invokes the left MFunction (`l`), printing an `x` to the left of the current tape location
leftTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R", "R"}, "l(ph(0))"}
// Invokes the findLeft MFunction (`fl`) printing an `x` to the left of the first ocurrence of the symb ol
findLeftTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "fl(ph(x), ph(y), 0)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, printAndHalt)
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, findLeft...)
possibleSymbols := []string{"e", "0", "1", "x", "y"}
t.Run("Left", func(t *testing.T) {
mConfigurations := append(mConfigurations, leftTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee0")
})
t.Run("FindLeft", func(t *testing.T) {
mConfigurations := append(mConfigurations, findLeftTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "1", " ", "1", " ", "0", " ", "0"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee1 1x0 0")
})
}
func TestFindRight(t *testing.T) {
// Invokes the right MFunction (`r`), printing an `x` to the right of the current tape location
rightTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "r(ph(x))"}
// Invokes the findRight MFunction (`fr`) printing an `x` to the right of the first ocurrence of the symb ol
findRightTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "fr(ph(x), ph(y), 0)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, printAndHalt)
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, findRight...)
possibleSymbols := []string{"e", "0", "1", "x", "y"}
t.Run("Right", func(t *testing.T) {
mConfigurations := append(mConfigurations, rightTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee0x")
})
t.Run("FindRight", func(t *testing.T) {
mConfigurations := append(mConfigurations, findRightTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "1", " ", "1", " ", "0", " ", "0"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee1 1 0x0")
})
}
func TestCopy(t *testing.T) {
// Invokes the copy MFunction (`c`), copying the `0` to the left of `x` to the end of the sequence.
copyTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "c(halt, halt, x)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, findLeft...)
mConfigurations = append(mConfigurations, printAtTheEnd...)
mConfigurations = append(mConfigurations, copy...)
possibleSymbols := []string{"e", "0", "x"}
t.Run("Copy", func(t *testing.T) {
mConfigurations := append(mConfigurations, copyTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "0", "x"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(30)
checkTape(t, m.TapeString(), "ee0 0x0")
})
}
func TestCopyAndErase(t *testing.T) {
// Invokes the copyAndErase MFunction (`ce`), copying the marked figure and erasing the marker.
copyAndEraseOnceTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "ce(halt, halt, x)"}
// Invokes the copyAndErase MFunction (`ce`), copying all of the marked figures and erasing all of the markers.
copyAndEraseAllTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "ce(halt, x)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, findLeft...)
mConfigurations = append(mConfigurations, printAtTheEnd...)
mConfigurations = append(mConfigurations, erase...)
mConfigurations = append(mConfigurations, copy...)
mConfigurations = append(mConfigurations, copyAndErase...)
possibleSymbols := []string{"e", "0", "1", "x"}
t.Run("CopyAndEraseOnce", func(t *testing.T) {
mConfigurations := append(mConfigurations, copyAndEraseOnceTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "0", "x"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(50)
checkTape(t, m.TapeString(), "ee0 0 0")
})
t.Run("CopyAndEraseAll", func(t *testing.T) {
mConfigurations := append(mConfigurations, copyAndEraseAllTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "1", "x", "0", "x"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(100)
checkTape(t, m.TapeString(), "ee0 1 0 1 0")
})
}
func TestReplace(t *testing.T) {
// Invokes the replace MFunction (`re`), replacing a marker with another.
replaceOnceTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "re(halt, halt, x, y)"}
// Invokes the replace MFunction (`re`), replace all markers with another.
replaceAllTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "re(halt, x, y)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, replace...)
possibleSymbols := []string{"e", "0", "x", "y"}
t.Run("ReplaceOnce", func(t *testing.T) {
mConfigurations := append(mConfigurations, replaceOnceTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", "x", "0", "x"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(100)
checkTape(t, m.TapeString(), "ee0y0x")
})
t.Run("ReplaceAll", func(t *testing.T) {
mConfigurations := append(mConfigurations, replaceAllTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", "x", "0", "x"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(100)
checkTape(t, m.TapeString(), "ee0y0y")
})
}
func TestCopyAndReplace(t *testing.T) {
// Invokes the copyAndReplace MFunction (`cr`), copying the marked figure and replacing the mark.
copyAndReplaceOnceTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "cr(halt, halt, x, y)"}
// Invokes the copyAndReplace MFunction (`cr`), copying the marked figures and replacing the marks.
copyAndReplaceAllTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "cr(halt, x, y)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, findLeft...)
mConfigurations = append(mConfigurations, printAtTheEnd...)
mConfigurations = append(mConfigurations, erase...)
mConfigurations = append(mConfigurations, copy...)
mConfigurations = append(mConfigurations, copyAndErase...)
mConfigurations = append(mConfigurations, replace...)
mConfigurations = append(mConfigurations, copyAndReplace...)
possibleSymbols := []string{"e", "0", "1", "x", "y"}
t.Run("CopyAndReplaceOnce", func(t *testing.T) {
mConfigurations := append(mConfigurations, copyAndReplaceOnceTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "0", "x"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(100)
checkTape(t, m.TapeString(), "ee0 0y0")
})
t.Run("CopyAndReplaceAll", func(t *testing.T) {
mConfigurations := append(mConfigurations, copyAndReplaceAllTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "1", "x", "0", "x"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(100)
checkTape(t, m.TapeString(), "ee0 1y0y1 0")
})
}
func TestCompare(t *testing.T) {
// Invokes the compare MFunction (`cp`), printing `z` at the end if neither markers exist.
compareNeitherExistTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "cp(halt, halt, pe(halt, z), x, y)"}
// Invokes the compare MFunction (`cp`), printing `z` at the end if the figures are not equal.
compareNotEqualTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "cp(halt, pe(halt, z), halt, x, y)"}
// Invokes the compare MFunction (`cp`), printing `z` at the end if the figures are equal.
compareEqualTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "cp(pe(halt, z), halt, halt, x, y)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, findLeft...)
mConfigurations = append(mConfigurations, printAtTheEnd...)
mConfigurations = append(mConfigurations, compare...)
possibleSymbols := []string{"e", "0", "1", "x", "y", "z"}
t.Run("CompareNeitherExist", func(t *testing.T) {
mConfigurations := append(mConfigurations, compareNeitherExistTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "0"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(100)
checkTape(t, m.TapeString(), "ee0 0 z")
})
t.Run("CompareNotEqual", func(t *testing.T) {
mConfigurations := append(mConfigurations, compareNotEqualTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", "x", "1", "y"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(100)
checkTape(t, m.TapeString(), "ee0x1yz")
})
t.Run("CompareEqual", func(t *testing.T) {
mConfigurations := append(mConfigurations, compareEqualTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", "x", "0", "y"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(100)
checkTape(t, m.TapeString(), "ee0x0yz")
})
}
func TestCompareAndErase(t *testing.T) {
// Invokes the compareAndErase MFunction (`cpe`), erasing the markers if the figures are equal.
compareAndEraseOnceTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "cpe(halt, halt, halt, x, y)"}
// Invokes the compareAndErase MFunction (`cpe`), erasing the markers if the sequence of figures are equal.
compareAndEraseAllTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "cpe(halt, halt, x, y)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, findLeft...)
mConfigurations = append(mConfigurations, printAtTheEnd...)
mConfigurations = append(mConfigurations, compare...)
mConfigurations = append(mConfigurations, erase...)
mConfigurations = append(mConfigurations, compareAndErase...)
possibleSymbols := []string{"e", "0", "1", "x", "y"}
t.Run("CompareAndEraseOnce", func(t *testing.T) {
mConfigurations := append(mConfigurations, compareAndEraseOnceTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", "x", "0", "y"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(200)
checkTape(t, m.TapeString(), "ee0 0 ")
})
t.Run("CompareAndEraseAll", func(t *testing.T) {
mConfigurations := append(mConfigurations, compareAndEraseAllTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", "x", "1", "x", "0", "y", "1", "y"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(200)
checkTape(t, m.TapeString(), "ee0 1 0 1 ")
})
}
func TestFindRightMost(t *testing.T) {
// Invokes the findRightMost MFunction (`g`) (which finds the end of the tape), and prints.
findEndOfTapeTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "g(ph(x))"}
// Invokes the findRightMost MFunction (`g`), and prints to the right of the found character.
findRightMostTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "g(prh(x), 0)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, printAndHalt)
mConfigurations = append(mConfigurations, printToRightAndHalt)
mConfigurations = append(mConfigurations, findRightMost...)
possibleSymbols := []string{"e", "x", "0", "1"}
t.Run("FindEndOfTape", func(t *testing.T) {
mConfigurations := append(mConfigurations, findEndOfTapeTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "1", " ", "0", " ", "1"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee0 1 0 1 x")
})
t.Run("FindRightMost", func(t *testing.T) {
mConfigurations := append(mConfigurations, findRightMostTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "1", " ", "0", " ", "1"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(20)
checkTape(t, m.TapeString(), "ee0 1 0x1")
})
}
func TestPrintAtTheEnd2(t *testing.T) {
// Invokes the printAtTheEnd2 MFunction (`pe2`), printing `x` and `y` at the end of the sequence
printAtTheEndTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "pe2(halt, x, y)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, printAtTheEnd...)
mConfigurations = append(mConfigurations, printAtTheEnd2...)
mConfigurations = append(mConfigurations, printAtTheEndTest)
possibleSymbols := []string{"e", "0", "x", "y"}
t.Run("PrintAtTheEnd2", func(t *testing.T) {
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", " ", "0"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(30)
checkTape(t, m.TapeString(), "ee0 0 x y")
})
}
func TestCopyAndErase2(t *testing.T) {
// Invokes the copyAndErase5 MFunction (`ce5`), copying all of the marked figures and erasing all of the markers.
copyAndEraseAll2Test := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "ce5(halt, x, s, t, u, v)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, findLeftMost...)
mConfigurations = append(mConfigurations, findLeft...)
mConfigurations = append(mConfigurations, printAtTheEnd...)
mConfigurations = append(mConfigurations, erase...)
mConfigurations = append(mConfigurations, copy...)
mConfigurations = append(mConfigurations, copyAndErase...)
mConfigurations = append(mConfigurations, copyAndErase2...)
possibleSymbols := []string{"e", "0", "1", "x", "s", "t", "u", "v"}
t.Run("CopyAndEraseAll2", func(t *testing.T) {
mConfigurations := append(mConfigurations, copyAndEraseAll2Test)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", "x", "0", "x", "0", "s", "1", "s", "1", "t", "0", "t", "1", "u", "1", "u", "0", "v", "0", "v", "0"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(1500)
checkTape(t, m.TapeString(), "ee0 0 0 1 1 0 1 1 0 0")
})
}
func TestEraseAll(t *testing.T) {
// Invokes the eraseAll MFunction (`e`), erasing all markers.
eraseAllTest := MConfiguration{"b", []string{"*", " "}, []string{"R", "R"}, "e(halt)"}
mConfigurations := []MConfiguration{}
mConfigurations = append(mConfigurations, eraseAll...)
possibleSymbols := []string{"e", "0", "x", "y"}
t.Run("EraseAll", func(t *testing.T) {
mConfigurations := append(mConfigurations, eraseAllTest)
m := NewMachine(NewAbbreviatedTable(AbbreviatedTableInput{
MConfigurations: mConfigurations,
Tape: []string{"e", "e", "0", "x", "0", " ", "0", "y"},
PossibleSymbols: possibleSymbols,
StartingMConfiguration: "b",
}))
m.MoveN(100)
checkTape(t, m.TapeString(), "ee0 0 0")
})
}