forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathUtilsExampleTest.java
More file actions
61 lines (50 loc) · 1.34 KB
/
MathUtilsExampleTest.java
File metadata and controls
61 lines (50 loc) · 1.34 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
package com.examplehub.basics.utils;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
class MathUtilsExampleTest {
@ParameterizedTest
@ValueSource(ints = {0, 1, 10, 99, 1000, 9999999})
void testAbs(int num) {
assertEquals(num, Math.abs(num));
}
@ParameterizedTest
@ValueSource(ints = {-10, -5, -1000})
void testNegativeAbs(int num) {
assertEquals(-num, Math.abs(num));
}
@Test
void testMax() {
assertEquals(3, Math.max(1, 3));
assertEquals(-1, Math.max(-1, -3));
assertEquals(-1.5, Math.max(-1.5, -3.27));
}
@Test
void testMin() {
assertEquals(1, Math.min(1, 3));
assertEquals(-3, Math.min(-1, -3));
assertEquals(-3.27, Math.min(-1.5, -3.27));
}
@Test
void testPower() {
assertEquals(1024, Math.pow(2, 10));
assertEquals(512, Math.pow(2, 9));
}
@Test
void testSqrt() {
assertEquals(2, Math.sqrt(4));
assertEquals(1.4142135623730951, Math.sqrt(2));
}
@Test
void testRandom() {
double randomNumber = Math.random();
assertTrue(randomNumber >= 0 && randomNumber < 1);
}
@Test
void testRound() {
assertEquals(3, Math.round(3.14));
assertEquals(4, Math.round(3.78));
assertEquals(-3, Math.round(-3.14));
}
}