forked from darmiel/Compilerbau23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestIntegerMachine.java
53 lines (44 loc) · 1.49 KB
/
TestIntegerMachine.java
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
import compiler.StateMachine;
import compiler.machines.IntegerMachine;
import java.io.OutputStreamWriter;
public class TestIntegerMachine {
public static void main(final String[] args) throws Exception {
final String[] testsOk = {
"0",
"+0",
"-0",
"1",
"12",
"12",
"101",
"-121",
"-101",
"12390309483840534089535",
"+653234"
};
final String[] testFail = {
"01",
"-01",
"+01",
"123ab456",
"a1",
};
for (final String s : testsOk) {
final StateMachine abMachine = new IntegerMachine();
final OutputStreamWriter outWriter = new OutputStreamWriter(System.out);
abMachine.process(s, outWriter);
if (!abMachine.isFinalState()) {
throw new Exception("expected state machine to ACCEPT: " + s);
}
}
System.out.println("\n\nNOW FAIL\n\n");
for (final String s : testFail) {
final StateMachine abMachine = new IntegerMachine();
final OutputStreamWriter outWriter = new OutputStreamWriter(System.out);
abMachine.process(s, outWriter);
if (abMachine.isFinalState()) {
throw new Exception("expected state machine to ACCEPT: " + s);
}
}
}
}