|
1 | 1 | package com.thealgorithms.slidingwindow;
|
2 | 2 |
|
3 |
| -import org.junit.jupiter.api.Test; |
4 |
| - |
5 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
6 | 4 |
|
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
7 | 7 | /**
|
8 | 8 | * Unit tests for ShortestCoprimeSegment algorithm
|
9 | 9 | *
|
10 |
| - * @author DomTr (https://github.com/DomTr) |
| 10 | + * @author DomTr (<a href="https://github.com/DomTr">...</a>) |
11 | 11 | */
|
12 | 12 | public class ShortestCoprimeSegmentTest {
|
13 | 13 | @Test
|
14 | 14 | public void testShortestCoprimeSegment() {
|
15 |
| - assertEquals(3, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[]{4, 6, 9, 3, 6})); |
16 |
| - assertEquals(2, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[]{4, 5, 9, 3, 6})); |
17 |
| - assertEquals(2, ShortestCoprimeSegment.shortestCoprimeSegment(2, new long[]{3, 2})); |
18 |
| - assertEquals(2, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[]{3, 9, 9, 9, 10})); |
19 |
| - assertEquals(4, ShortestCoprimeSegment.shortestCoprimeSegment(4, new long[]{3 * 7, 7 * 5, 5 * 7 * 3, 3 * 5})); |
20 |
| - assertEquals(4, ShortestCoprimeSegment.shortestCoprimeSegment(4, new long[]{3 * 11, 11 * 7, 11 * 7 * 3, 3 * 7})); |
21 |
| - assertEquals(5, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[]{3 * 11, 11 * 7, 11 * 7 * 3, 11 * 7 * 3 * 5, 5 * 7})); |
22 |
| - assertEquals(6, ShortestCoprimeSegment.shortestCoprimeSegment(6, new long[]{3 * 11, 11 * 7, 11 * 7 * 3, 11 * 7 * 3 * 5, 11 * 7 * 3 * 5 * 13, 7 * 13})); |
23 |
| - assertEquals(6, ShortestCoprimeSegment.shortestCoprimeSegment(7, new long[]{3 * 11, 11 * 7, 11 * 7 * 3, 11 * 7 * 3 * 5, 11 * 7 * 3 * 5 * 13, 7 * 13, 11 * 7 * 3 * 5 * 13})); |
24 |
| - assertEquals(10, ShortestCoprimeSegment.shortestCoprimeSegment(10, new long[]{3 * 11, 7 * 11, 3 * 7 * 11, 3 * 5 * 7 * 11, 3 * 5 * 7 * 11 * 13, 2 * 3 * 5 * 7 * 11 * 13, 2 * 3 * 5 * 7 * 11 * 13 * 17, 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19, 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23, 7 * 13})); |
| 15 | + assertEquals(3, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[] {4, 6, 9, 3, 6})); |
| 16 | + assertEquals(2, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[] {4, 5, 9, 3, 6})); |
| 17 | + assertEquals(2, ShortestCoprimeSegment.shortestCoprimeSegment(2, new long[] {3, 2})); |
| 18 | + assertEquals(2, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[] {3, 9, 9, 9, 10})); |
| 19 | + assertEquals(4, ShortestCoprimeSegment.shortestCoprimeSegment(4, new long[] {3 * 7, 7 * 5, 5 * 7 * 3, 3 * 5})); |
| 20 | + assertEquals(4, ShortestCoprimeSegment.shortestCoprimeSegment(4, new long[] {3 * 11, 11 * 7, 11 * 7 * 3, 3 * 7})); |
| 21 | + assertEquals(5, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[] {3 * 11, 11 * 7, 11 * 7 * 3, 11 * 7 * 3 * 5, 5 * 7})); |
| 22 | + assertEquals(6, ShortestCoprimeSegment.shortestCoprimeSegment(6, new long[] {3 * 11, 11 * 7, 11 * 7 * 3, 11 * 7 * 3 * 5, 11 * 7 * 3 * 5 * 13, 7 * 13})); |
| 23 | + assertEquals(6, ShortestCoprimeSegment.shortestCoprimeSegment(7, new long[] {3 * 11, 11 * 7, 11 * 7 * 3, 11 * 7 * 3 * 5, 11 * 7 * 3 * 5 * 13, 7 * 13, 11 * 7 * 3 * 5 * 13})); |
| 24 | + assertEquals(10, ShortestCoprimeSegment.shortestCoprimeSegment(10, new long[] {3 * 11, 7 * 11, 3 * 7 * 11, 3 * 5 * 7 * 11, 3 * 5 * 7 * 11 * 13, 2 * 3 * 5 * 7 * 11 * 13, 2 * 3 * 5 * 7 * 11 * 13 * 17, 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19, 2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23, 7 * 13})); |
25 | 25 | // Segment can consist of one element
|
26 |
| - assertEquals(1, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[]{4, 6, 1, 3, 6})); |
27 |
| - assertEquals(1, ShortestCoprimeSegment.shortestCoprimeSegment(1, new long[]{1})); |
| 26 | + assertEquals(1, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[] {4, 6, 1, 3, 6})); |
| 27 | + assertEquals(1, ShortestCoprimeSegment.shortestCoprimeSegment(1, new long[] {1})); |
28 | 28 | }
|
29 | 29 |
|
30 | 30 | @Test
|
31 | 31 | public void testNoCoprimeSegment() {
|
32 | 32 | // There may not be a coprime segment
|
33 |
| - assertEquals(-1, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[]{4, 6, 8, 12, 8})); |
34 |
| - assertEquals(-1, ShortestCoprimeSegment.shortestCoprimeSegment(10, new long[]{4, 4, 4, 4, 10, 4, 6, 8, 12, 8})); |
35 |
| - assertEquals(-1, ShortestCoprimeSegment.shortestCoprimeSegment(1, new long[]{100})); |
36 |
| - assertEquals(-1, ShortestCoprimeSegment.shortestCoprimeSegment(3, new long[]{2, 2, 2})); |
37 |
| - |
| 33 | + assertEquals(-1, ShortestCoprimeSegment.shortestCoprimeSegment(5, new long[] {4, 6, 8, 12, 8})); |
| 34 | + assertEquals(-1, ShortestCoprimeSegment.shortestCoprimeSegment(10, new long[] {4, 4, 4, 4, 10, 4, 6, 8, 12, 8})); |
| 35 | + assertEquals(-1, ShortestCoprimeSegment.shortestCoprimeSegment(1, new long[] {100})); |
| 36 | + assertEquals(-1, ShortestCoprimeSegment.shortestCoprimeSegment(3, new long[] {2, 2, 2})); |
38 | 37 | }
|
39 | 38 | }
|
0 commit comments