-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorTest.java
More file actions
95 lines (81 loc) · 2.73 KB
/
CalculatorTest.java
File metadata and controls
95 lines (81 loc) · 2.73 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
package ru.spbau.mit.alyokhina;
import org.junit.Test;
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
public class CalculatorTest {
@Test
public void testGetRPN() {
Stack<String> expression = mock(Stack.class);
Stack<String> operand = mock(Stack.class);
Stack<String> rpn = mock(Stack.class);
when(expression.isEmpty())
.thenReturn(false)
.thenReturn(false)
.thenReturn(false)
.thenReturn(false)
.thenReturn(false)
.thenReturn(false)
.thenReturn(false)
.thenReturn(true);
when(expression.pop())
.thenReturn("(")
.thenReturn("1")
.thenReturn("+")
.thenReturn("3")
.thenReturn(")")
.thenReturn("*")
.thenReturn("2");
when(operand.isEmpty())
.thenReturn(true)
.thenReturn(false)
.thenReturn(false)
.thenReturn(false)
.thenReturn(true)
.thenReturn(false)
.thenReturn(true);
when(operand.peek())
.thenReturn("+")
.thenReturn("(");
when(operand.pop())
.thenReturn("+")
.thenReturn("(")
.thenReturn("*");
Calculator calculator = new Calculator(expression, operand, rpn);
assertEquals(" 1 3 + 2 *", calculator.getRPN());
verify(operand).push("(");
verify(rpn).push("1");
verify(operand).push("+");
verify(rpn).push("3");
verify(rpn).push("+");
verify(operand).push("*");
verify(rpn).push("2");
verify(rpn).push("*");
}
@Test
public void testCalculate() {
Stack<String> expression = mock(Stack.class);
Stack<String> operand = mock(Stack.class);
Stack<String> rpn = mock(Stack.class);
when(rpn.isEmpty())
.thenReturn(false)
.thenReturn(false)
.thenReturn(false)
.thenReturn(false)
.thenReturn(false)
.thenReturn(true);
when(rpn.peek())
.thenReturn("*")
.thenReturn("2")
.thenReturn("+")
.thenReturn("3")
.thenReturn("1");
when(rpn.pop())
.thenReturn("*")
.thenReturn("2")
.thenReturn("+")
.thenReturn("3")
.thenReturn("1");
Calculator calculator = new Calculator(expression, operand, rpn);
assertEquals((Double) 8.0, calculator.calculate());
}
}