-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpressionParserPartialTester.java
More file actions
executable file
·106 lines (95 loc) · 3.25 KB
/
ExpressionParserPartialTester.java
File metadata and controls
executable file
·106 lines (95 loc) · 3.25 KB
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
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import java.util.*;
import java.io.*;
/**
* Code to test Project 5; you should definitely add more tests!
*/
public class ExpressionParserPartialTester {
private ExpressionParser _parser;
@Before
/**
* Instantiates the actors and movies graphs
*/
public void setUp () throws IOException {
_parser = new SimpleExpressionParser();
}
@Test
/**
* Just verifies that the SimpleExpressionParser could be instantiated without crashing.
*/
public void finishedLoading () {
assertTrue(true);
// Yay! We didn't crash
}
@Test
/**
* Verifies that a specific expression is parsed into the correct parse tree.
*/
public void testExpression1 () throws ExpressionParseException {
final String expressionStr = "a+b";
final String parseTreeStr = "+\n\ta\n\tb\n";
assertEquals(parseTreeStr, _parser.parse(expressionStr, false).convertToString(0));
}
@Test
/**
* Verifies that a specific expression is parsed into the correct parse tree.
*/
public void testExpression2 () throws ExpressionParseException {
final String expressionStr = "13*x";
final String parseTreeStr = "*\n\t13\n\tx\n";
assertEquals(parseTreeStr, _parser.parse(expressionStr, false).convertToString(0));
}
@Test
/**
* Verifies that a specific expression is parsed into the correct parse tree.
*/
public void testExpression3 () throws ExpressionParseException {
final String expressionStr = "4*(z+5*x)";
final String parseTreeStr = "*\n\t4\n\t()\n\t\t+\n\t\t\tz\n\t\t\t*\n\t\t\t\t5\n\t\t\t\tx\n";
assertEquals(parseTreeStr, _parser.parse(expressionStr, false).convertToString(0));
}
@Test
/**
* Verifies that a specific expression is parsed into the correct parse tree.
*/
public void testExpressionAndFlatten1 () throws ExpressionParseException {
final String expressionStr = "1+2+3";
final String parseTreeStr = "+\n\t1\n\t2\n\t3\n";
assertEquals(parseTreeStr, _parser.parse(expressionStr, false).convertToString(0));
}
@Test
/**
* Verifies that a specific expression is parsed into the correct parse tree.
*/
public void testExpressionAndFlatten2 () throws ExpressionParseException {
final String expressionStr = "(x+(x)+(x+x)+x)";
final String parseTreeStr = "()\n\t+\n\t\tx\n\t\t()\n\t\t\tx\n\t\t()\n\t\t\t+\n\t\t\t\tx\n\t\t\t\tx\n\t\tx\n";
assertEquals(parseTreeStr, _parser.parse(expressionStr, false).convertToString(0));
}
@Test(expected = ExpressionParseException.class)
/**
* Verifies that a specific expression is parsed into the correct parse tree.
*/
public void testException1 () throws ExpressionParseException {
final String expressionStr = "1+2+";
_parser.parse(expressionStr, false);
}
@Test(expected = ExpressionParseException.class)
/**
* Verifies that a specific expression is parsed into the correct parse tree.
*/
public void testException2 () throws ExpressionParseException {
final String expressionStr = "((()))";
_parser.parse(expressionStr, false);
}
@Test(expected = ExpressionParseException.class)
/**
* Verifies that a specific expression is parsed into the correct parse tree.
*/
public void testException3 () throws ExpressionParseException {
final String expressionStr = "()()";
_parser.parse(expressionStr, false);
}
}