|
2 | 2 |
|
3 | 3 | import org.junit.Test; |
4 | 4 |
|
5 | | -import static org.hamcrest.CoreMatchers.is; |
6 | | -import static org.hamcrest.MatcherAssert.assertThat; |
| 5 | +import static by.andd3dfx.numeric.LeastCommonMultiple.find; |
| 6 | +import static by.andd3dfx.numeric.LeastCommonMultiple.find_usingGCD; |
| 7 | +import static org.assertj.core.api.Assertions.assertThat; |
| 8 | +import static org.junit.Assert.assertThrows; |
7 | 9 |
|
8 | 10 | public class LeastCommonMultipleTest { |
9 | 11 |
|
10 | 12 | @Test |
11 | 13 | public void testFind() { |
12 | | - assertThat(LeastCommonMultiple.find(new int[]{10}), is(10)); |
13 | | - assertThat(LeastCommonMultiple.find(new int[]{11}), is(11)); |
| 14 | + assertThrows("Numbers array should be populated!", |
| 15 | + IllegalArgumentException.class, () -> find(new int[]{})); |
14 | 16 |
|
15 | | - assertThat(LeastCommonMultiple.find(new int[]{2, 3}), is(6)); |
16 | | - assertThat(LeastCommonMultiple.find(new int[]{4, 6}), is(12)); |
17 | | - // 6240 = 10*4*2*2*39 |
18 | | - // 6800 = 10*4*2*5*17 |
19 | | - assertThat(LeastCommonMultiple.find(new int[]{6240, 6800}), is(10 * 4 * 2 * 2 * 39 * 5 * 17)); |
| 17 | + assertThat(find(new int[]{10})).isEqualTo(10); |
| 18 | + assertThat(find(new int[]{11})).isEqualTo(11); |
20 | 19 |
|
21 | | - assertThat(LeastCommonMultiple.find(new int[]{6, 9, 20}), is(180)); |
| 20 | + assertThat(find(new int[]{2, 3})).isEqualTo(6); |
| 21 | + assertThat(find(new int[]{4, 6})).isEqualTo(12); |
| 22 | + // 6240 = 2^5 * 3 * 5 * 13 |
| 23 | + // 6800 = 2^4 * 5^2 * 17 |
| 24 | + // НОК(6240, 6800) = 2^5 * 3 * 5^2 * 13 * 17 |
| 25 | + assertThat(find(new int[]{6240, 6800})).isEqualTo(530_400); |
| 26 | + |
| 27 | + assertThat(find(new int[]{6, 9, 20})).isEqualTo(180); |
22 | 28 | } |
23 | 29 |
|
24 | 30 | @Test |
25 | 31 | public void testFind_usingGCD() { |
26 | | - assertThat(LeastCommonMultiple.find_usingGCD(new int[]{10}), is(10)); |
27 | | - assertThat(LeastCommonMultiple.find_usingGCD(new int[]{11}), is(11)); |
| 32 | + assertThrows("Numbers array should be populated!", |
| 33 | + IllegalArgumentException.class, () -> find_usingGCD(new int[]{})); |
| 34 | + |
| 35 | + assertThat(find_usingGCD(new int[]{10})).isEqualTo(10); |
| 36 | + assertThat(find_usingGCD(new int[]{11})).isEqualTo(11); |
28 | 37 |
|
29 | | - assertThat(LeastCommonMultiple.find_usingGCD(new int[]{2, 3}), is(6)); |
30 | | - assertThat(LeastCommonMultiple.find_usingGCD(new int[]{4, 6}), is(12)); |
31 | | - // 6240 = 10*4*2*2*39 |
32 | | - // 6800 = 10*4*2*5*17 |
33 | | - assertThat(LeastCommonMultiple.find_usingGCD(new int[]{6240, 6800}), is(10 * 4 * 2 * 2 * 39 * 5 * 17)); |
| 38 | + assertThat(find_usingGCD(new int[]{2, 3})).isEqualTo(6); |
| 39 | + assertThat(find_usingGCD(new int[]{4, 6})).isEqualTo(12); |
| 40 | + // 6240 = 2^5 * 3 * 5 * 13 |
| 41 | + // 6800 = 2^4 * 5^2 * 17 |
| 42 | + // НОК(6240, 6800) = 2^5 * 3 * 5^2 * 13 * 17 |
| 43 | + assertThat(find_usingGCD(new int[]{6240, 6800})).isEqualTo(530_400); |
34 | 44 |
|
35 | | - assertThat(LeastCommonMultiple.find_usingGCD(new int[]{6, 9, 20}), is(180)); |
| 45 | + assertThat(find_usingGCD(new int[]{6, 9, 20})).isEqualTo(180); |
36 | 46 | } |
37 | 47 | } |
0 commit comments