forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOddCheckTest.java
More file actions
41 lines (32 loc) · 909 Bytes
/
OddCheckTest.java
File metadata and controls
41 lines (32 loc) · 909 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
package com.examplehub.maths;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.examplehub.utils.RandomUtils;
import org.junit.jupiter.api.Test;
class OddCheckTest {
@Test
void isOdd() {
for (int i = -99; i <= 99; i += 2) {
assertTrue(OddCheck.isOdd(i));
}
}
@Test
void isOddFaster() {
for (int i = -99; i <= 99; i += 2) {
assertTrue(OddCheck.isOddFaster(i));
}
}
void testSpeed() {
int[] ints = RandomUtils.randomInts(-1000, 1000, Integer.MAX_VALUE);
long startTime = System.nanoTime();
for (int j : ints) {
boolean isOdd = OddCheck.isOdd(j);
}
long slowTime = System.nanoTime() - startTime;
startTime = System.nanoTime();
for (int anInt : ints) {
boolean isOdd = OddCheck.isOddFaster(anInt);
}
long fasterTime = System.nanoTime() - startTime;
assertTrue(fasterTime < slowTime);
}
}