-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOperatorTests.java
More file actions
67 lines (65 loc) · 1.67 KB
/
Copy pathOperatorTests.java
File metadata and controls
67 lines (65 loc) · 1.67 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
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.*;
import java.util.*;
public class OperatorTests {
Expr const10;
Expr const20;
@Before
public void init() {
const10 = new Constant(10);
const20 = new Constant(20);
}
@Test
public void testAddOperator1() {
Plus tenPlusTwenty = new Plus(const10, const20);
int result = tenPlusTwenty.eval();
assertEquals(30, result);
}
@Test
public void testAddOperator2() {
Expr tenPlusTwenty = new Plus(const10, const20);
int result = tenPlusTwenty.eval();
assertEquals(30, result);
}
@Test
public void testConstant() {
Expr ten = const10;
int result = ten.eval();
assertEquals(10, result);
}
@Test(expected = IllegalArgumentException.class)
public void testNullArgsForPlusOperator() {
Expr invalidPlus = new Plus(null, null);
}
@Test
public void testMultOperator1() {
Mult tenMultTwenty = new Mult(const10, const20);
int result = tenMultTwenty.eval();
assertEquals(200, result);
}
@Test
public void testMultOperator2() {
Expr tenMultTwenty = new Mult(const10, const20);
int result = tenMultTwenty.eval();
assertEquals(200, result);
}
@Test
public void testDivOperator1() {
Expr tenDivTwenty = new Div(const10, const20);
int result = tenDivTwenty.eval();
assertEquals(0, result);
}
@Test
public void testDivOperator2() {
Expr twentyDivTen = new Div(const20, const10);
int result = twentyDivTen.eval();
assertEquals(2, result);
}
@Test(expected = ArithmeticException.class)
public void testDivByZero() {
Expr divByZero = new Div(const20, new Constant(0));
divByZero.eval();
}
}