Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e89a9fb

Browse files
committed
MathTest.java
1 parent 4def651 commit e89a9fb

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

simple-junit/MathTest.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.hmkcode.junit;
2+
3+
import static org.junit.Assert.assertThat;
4+
5+
import org.junit.Rule;
6+
import org.junit.Test;
7+
import org.junit.Ignore;
8+
import org.junit.rules.Timeout;
9+
import org.junit.runner.RunWith;
10+
import org.junit.runners.JUnit4;
11+
import static org.hamcrest.CoreMatchers.not;
12+
import static org.hamcrest.CoreMatchers.is;
13+
14+
15+
/**
16+
* Tests for {@link Functions}.
17+
*
18+
* @author hmkcode@gmail.com (Hani HMK)
19+
*/
20+
@RunWith(JUnit4.class)
21+
public class MathTest {
22+
23+
@Rule
24+
public Timeout globalTimeout = new Timeout(3000); // 0 seconds max per method tested
25+
26+
27+
com.hmkcode.junit.Math math = new com.hmkcode.junit.Math();
28+
29+
30+
@Test
31+
@Ignore
32+
public void testAssertNotNull() {
33+
org.junit.Assert.assertNotNull("should not be null", math);
34+
}
35+
36+
@Test
37+
public void testSum(){
38+
org.junit.Assert.assertTrue("failure - not equal", math.sum(3, 2) == 5);
39+
40+
//to test timeout
41+
/*for (;;) {
42+
}*/
43+
}
44+
45+
@Test
46+
public void testMultiply(){
47+
org.junit.Assert.assertTrue("failure - not equal", math.multiply(3, 2) == 6);
48+
}
49+
50+
@Test
51+
public void testDivide(){
52+
double x = 3,y = 2;
53+
assertThat("failure - can't divide by 0",y, is(not(0.0)));
54+
org.junit.Assert.assertTrue("failure - not equal", math.divide(x, y) == 1.5);
55+
}
56+
57+
@Test
58+
public void testSubtract(){
59+
org.junit.Assert.assertTrue("failure - not equal", math.subtract(3, 2) == 1);
60+
}
61+
62+
public static void main(String[] args){
63+
org.junit.runner.JUnitCore.runClasses(MathTest.class);
64+
65+
}
66+
}
67+

0 commit comments

Comments
 (0)