-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathLeastCommonMultipleTest.java
47 lines (36 loc) · 1.72 KB
/
LeastCommonMultipleTest.java
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
package by.andd3dfx.numeric;
import org.junit.Test;
import static by.andd3dfx.numeric.LeastCommonMultiple.find;
import static by.andd3dfx.numeric.LeastCommonMultiple.find_usingGCD;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
public class LeastCommonMultipleTest {
@Test
public void testFind() {
assertThrows("Numbers array should be populated!",
IllegalArgumentException.class, () -> find(new int[]{}));
assertThat(find(new int[]{10})).isEqualTo(10);
assertThat(find(new int[]{11})).isEqualTo(11);
assertThat(find(new int[]{2, 3})).isEqualTo(6);
assertThat(find(new int[]{4, 6})).isEqualTo(12);
// 6240 = 2^5 * 3 * 5 * 13
// 6800 = 2^4 * 5^2 * 17
// НОК(6240, 6800) = 2^5 * 3 * 5^2 * 13 * 17
assertThat(find(new int[]{6240, 6800})).isEqualTo(530_400);
assertThat(find(new int[]{6, 9, 20})).isEqualTo(180);
}
@Test
public void testFind_usingGCD() {
assertThrows("Numbers array should be populated!",
IllegalArgumentException.class, () -> find_usingGCD(new int[]{}));
assertThat(find_usingGCD(new int[]{10})).isEqualTo(10);
assertThat(find_usingGCD(new int[]{11})).isEqualTo(11);
assertThat(find_usingGCD(new int[]{2, 3})).isEqualTo(6);
assertThat(find_usingGCD(new int[]{4, 6})).isEqualTo(12);
// 6240 = 2^5 * 3 * 5 * 13
// 6800 = 2^4 * 5^2 * 17
// НОК(6240, 6800) = 2^5 * 3 * 5^2 * 13 * 17
assertThat(find_usingGCD(new int[]{6240, 6800})).isEqualTo(530_400);
assertThat(find_usingGCD(new int[]{6, 9, 20})).isEqualTo(180);
}
}