forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvenCheckTest.java
More file actions
45 lines (36 loc) · 1.05 KB
/
EvenCheckTest.java
File metadata and controls
45 lines (36 loc) · 1.05 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
package com.examplehub.maths;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.examplehub.utils.RandomUtils;
import org.junit.jupiter.api.Test;
class EvenCheckTest {
@Test
void isEven() {
for (int i = -100; i <= 100; i += 2) {
assertTrue(EvenCheck.isEven(i));
assertFalse(EvenCheck.isEven(i + 1));
}
}
@Test
void isEvenFaster() {
for (int i = -100; i <= 100; i += 2) {
assertTrue(EvenCheck.isEvenFaster(i));
assertFalse(EvenCheck.isEvenFaster(i + 1));
}
}
@Test
void testSpeed() {
int[] ints = RandomUtils.randomInts(-1000, 1000, 99999999);
long startTime = System.nanoTime();
for (int j : ints) {
boolean isEven = EvenCheck.isEven(j);
}
long slowTime = System.nanoTime() - startTime;
startTime = System.nanoTime();
for (int anInt : ints) {
boolean isEven = EvenCheck.isEven(anInt);
}
long fasterTime = System.nanoTime() - startTime;
assertTrue(fasterTime <= slowTime);
}
}