|
| 1 | +package com.thealgorithms.others; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +class ArrayRightRotationTest { |
| 8 | + |
| 9 | + @Test |
| 10 | + void testArrayRightRotation() { |
| 11 | + int[] arr = {1, 2, 3, 4, 5, 6, 7}; |
| 12 | + int k = 3; |
| 13 | + int[] expected = {5, 6, 7, 1, 2, 3, 4}; |
| 14 | + int[] result = ArrayRightRotation.rotateRight(arr, k); |
| 15 | + assertArrayEquals(expected, result); |
| 16 | + } |
| 17 | + |
| 18 | + @Test |
| 19 | + void testArrayRightRotationWithZeroSteps() { |
| 20 | + int[] arr = {1, 2, 3, 4, 5, 6, 7}; |
| 21 | + int k = 0; |
| 22 | + int[] expected = {1, 2, 3, 4, 5, 6, 7}; |
| 23 | + int[] result = ArrayRightRotation.rotateRight(arr, k); |
| 24 | + assertArrayEquals(expected, result); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + void testArrayRightRotationWithEqualSizeSteps() { |
| 29 | + int[] arr = {1, 2, 3, 4, 5, 6, 7}; |
| 30 | + int k = arr.length; |
| 31 | + int[] expected = {1, 2, 3, 4, 5, 6, 7}; |
| 32 | + int[] result = ArrayRightRotation.rotateRight(arr, k); |
| 33 | + assertArrayEquals(expected, result); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + void testArrayRightRotationWithLowerSizeSteps() { |
| 38 | + int[] arr = {1, 2, 3, 4, 5, 6, 7}; |
| 39 | + int k = 2; |
| 40 | + int[] expected = {6, 7, 1, 2, 3, 4, 5}; |
| 41 | + int[] result = ArrayRightRotation.rotateRight(arr, k); |
| 42 | + assertArrayEquals(expected, result); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void testArrayRightRotationWithHigherSizeSteps() { |
| 47 | + int[] arr = {1, 2, 3, 4, 5, 6, 7}; |
| 48 | + int k = 10; |
| 49 | + int[] expected = {5, 6, 7, 1, 2, 3, 4}; |
| 50 | + int[] result = ArrayRightRotation.rotateRight(arr, k); |
| 51 | + assertArrayEquals(expected, result); |
| 52 | + } |
| 53 | +} |
0 commit comments