-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_turing.c
88 lines (73 loc) · 1.88 KB
/
test_turing.c
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
#include "turing.h"
#include <assert.h>
#include <stdlib.h>
void test1() {
//in
State states[] = {
{{BIT_1, BIT_1}, {Right, Stay}, {1, 1}},
{{BIT_0,BIT_1}, {Left, Stay}, {-1, 0}}
};
//reading 0 writing 1 right step going 1
//reading 0 writing 0 haulting
Tape tape = initTape();
if(runTuring(states,&tape, 10)){
perror("too long\n");
exit(1);
}
assert(readTape(&tape, 0) == BIT_1);
printf("test1 passed\n");
freeTape(tape);
}
void test2() {
State states[] = {{{BIT_0, BIT_1}, {Stay, Right}, {-1, -1}}};
Tape tape = initTape();
readTape(&tape,100);//actually alocate the mmemory
tape.pos.data[0] = BIT_1;
tape.pos.data[1] = BIT_0;
if(runTuring(states,&tape, 10)){
perror("too long\n");
exit(1);
}
assert(readTape(&tape, 1) == BIT_0);
assert(readTape(&tape, 2) == BIT_0);
assert(readTape(&tape, 3) == BIT_0);
printf("test2 passed\n");
freeTape(tape);
}
void test3() {
State states[] = {{{BIT_1, BIT_0}, {Right, Right}, {-1, 0}}};
Tape tape = initTape();
readTape(&tape,100);//actually alocate the mmemory
for (int i = 0; i < 4; i++) {
tape.pos.data[i] = BIT_1;
}
if(runTuring(states,&tape, 10)){
perror("too long\n");
exit(1);
}
assert(readTape(&tape, 4) == BIT_1);
printf("test3 passed\n");
freeTape(tape);
}
void test4() {
State states[] = {{{BIT_1, BIT_0}, {Right, Right}, {0, 0}}};
Tape tape = initTape();
if(!runTuring(states,&tape, 10)){
perror("didnt error on no hault\n");
exit(1);
}
printf("test4 passed\n");
freeTape(tape);
}
int main() {
printf("very basic tests\n");
//printf("\ntest1\n\n");
test1();
//printf("\ntest2\n\n");
test2();
//printf("\ntest3\n\n");
test3();
//printf("\ntest4\n\n");
test4();
return 0;
}