forked from Hari25cs/SampleWebApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCalculator.java
More file actions
54 lines (39 loc) · 990 Bytes
/
TestCalculator.java
File metadata and controls
54 lines (39 loc) · 990 Bytes
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
package junit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestCalculator {
private math.Calculator calc;
@Before
public void setUp() throws Exception {
calc = new math.Calculator();
}
@After
public void tearDown() throws Exception {
calc = null;
}
@Test
public void testAdd() {
double result = calc.add(10,20);
org.junit.Assert.assertEquals(30, result, 0);
}
@Test
public void testSubtract() {
double result = calc.subtract(100,50);
org.junit.Assert.assertEquals(50, result, 0);
}
@Test
public void testMultiply() {
double result = calc.multiply(2.5, 100);
org.junit.Assert.assertEquals(250, result, 0);
}
@Test
public void testDivide() {
double result = calc.divide(100, 10);
org.junit.Assert.assertEquals(10, result, 0.001);
}
@Test(expected = ArithmeticException.class)
public void testDivideByZero() {
calc.divide(100.5, 0);
}
}