forked from darmiel/Compilerbau23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestDecimalMachine.java
50 lines (43 loc) · 1.41 KB
/
TestDecimalMachine.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
import compiler.machines.DecimalMachine;
public class TestDecimalMachine {
private static final String[] acceptCases = {
"0.0",
"1.5320",
"0.5320",
"-1.5320",
"-0.5320",
"-10012323.532",
"10012323.532e5",
"10012323.532E-5"
};
private static final String[] denyCases = {
"0",
"01.0",
"1.",
"01.5320",
"01.532",
"-01.5320",
"-01.532",
"10012323.532e-5.5",
"10012323.532E-5.5",
"10012323.532E05"
};
public static void main(String[] args) throws Exception {
compiler.StateMachine decimalMachine;
java.io.OutputStreamWriter outWriter = new java.io.OutputStreamWriter(System.out);
// Accept cases:
for(final String input : acceptCases) {
decimalMachine = new DecimalMachine();
decimalMachine.process(input, outWriter);
if(!decimalMachine.isFinalState())
throw new Exception("Machine should have returned ACCEPT with input '" + input + "'");
}
// Deny cases:
for(final String input : denyCases) {
decimalMachine = new DecimalMachine();
decimalMachine.process(input, outWriter);
if(decimalMachine.isFinalState())
throw new Exception("Machine should have returned FAIL with input '" + input + "'");
}
}
}