-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTokenTest.java
115 lines (100 loc) · 2.95 KB
/
TokenTest.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
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
package proj4;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
/**
*
* Write a description of class TokenTest here.
*
* @author (your name)
* @version (a version number or a date)
*
*/
public class TokenTest {
@Rule
public Timeout timeout = Timeout.millis(100);
private Stack<Operator> stack;
private Stack<Token> stack2;
@Before
public void setUp() throws Exception {
stack = new Stack<Operator>();
stack2 = new Stack<Token>();
}
@After
public void tearDown() throws Exception {
stack = null;
stack2 = null;
}
@Test
public void testDivideOpContruct(){
Divide d = new Divide();
stack.push(d);
stack2.push(d);
LeftParen m = new LeftParen();
stack2.push(m);
}
@Test
public void testMultiplyOpContruct(){
Multiply d = new Multiply();
stack.push(d);
stack2.push(d);
LeftParen m = new LeftParen();
stack2.push(m);
assertEquals("{>*}", stack.toString());
assertEquals("{>(, *}", stack2.toString());
}
@Test
public void testLeftParenContruct(){
LeftParen m = new LeftParen();
stack2.push(m);
}
@Test
public void testInstanceOf(){
Token d = new Divide();
LeftParen m = new LeftParen();
assertEquals(true, m instanceof Token);
assertEquals(false, m instanceof Operator);
assertEquals(true, d instanceof Token);
assertEquals(true, d instanceof Operator);
}
@Test
public void testRightParenHandle(){
stack2.push(new LeftParen());
stack2.push(new Plus());
stack2.push(new Multiply());
stack2.push(new LeftParen());
stack2.push(new Minus());
assertEquals("{>-, (, *, +, (}", stack2.toString());
RightParen rP = new RightParen();
String s = rP.handle(stack2);
assertEquals("-", s);
assertEquals("{>*, +, (}", stack2.toString());
s = rP.handle(stack2);
assertEquals("*+", s);
assertEquals("{>}", stack2.toString());
}
@Test
public void testSemiColon(){
Semicolon sC = new Semicolon();
String s = sC.handle(stack2);
assertEquals("{>}", stack2.toString());
assertEquals("", s);
stack2.push(new Divide());
assertEquals("{>/}", stack2.toString());
s = sC.handle(stack2);
assertEquals("{>}", stack2.toString());
assertEquals("/", s);
}
@Test
public void testMulitply(){
Multiply m = new Multiply();
stack2.push(new LeftParen());
stack2.push(new Plus());
String s = m.handle(stack2);
assertEquals("", s);
assertEquals("{>*, +, (}", stack2.toString());
}
}