|
4 | 4 |
|
5 | 5 | import org.junit.jupiter.api.Test; |
6 | 6 |
|
7 | | -public class ArrayRotationTest { |
| 7 | +class ArrayLeftRotationTest { |
8 | 8 |
|
9 | 9 | @Test |
10 | | - void shouldRotateArrayRightByTwoPositions() { |
11 | | - int[] values = {1, 2, 3, 4, 5}; |
12 | | - |
13 | | - ArrayRotation.rotateRight(values, 2); |
14 | | - |
15 | | - assertArrayEquals(new int[] {4, 5, 1, 2, 3}, values); |
| 10 | + void testForOneElement() { |
| 11 | + int[] arr = {3}; |
| 12 | + int[] result = ArrayLeftRotation.rotateLeft(arr, 3); |
| 13 | + assertArrayEquals(arr, result); |
16 | 14 | } |
17 | 15 |
|
18 | 16 | @Test |
19 | | - void shouldRotateArrayLeftByTwoPositions() { |
20 | | - int[] values = {1, 2, 3, 4, 5}; |
21 | | - |
22 | | - ArrayRotation.rotateLeft(values, 2); |
23 | | - |
24 | | - assertArrayEquals(new int[] {3, 4, 5, 1, 2}, values); |
| 17 | + void testForZeroStep() { |
| 18 | + int[] arr = {3, 1, 5, 8, 6}; |
| 19 | + int[] result = ArrayLeftRotation.rotateLeft(arr, 0); |
| 20 | + assertArrayEquals(arr, result); |
25 | 21 | } |
26 | 22 |
|
27 | 23 | @Test |
28 | | - void shouldHandleRotationGreaterThanArrayLength() { |
29 | | - int[] values = {10, 20, 30, 40}; |
30 | | - |
31 | | - ArrayRotation.rotateRight(values, 6); |
32 | | - |
33 | | - assertArrayEquals(new int[] {30, 40, 10, 20}, values); |
| 24 | + void testForEqualSizeStep() { |
| 25 | + int[] arr = {3, 1, 5, 8, 6}; |
| 26 | + int[] result = ArrayLeftRotation.rotateLeft(arr, 5); |
| 27 | + assertArrayEquals(arr, result); |
34 | 28 | } |
35 | 29 |
|
36 | 30 | @Test |
37 | | - void shouldKeepSingleElementArrayUnchanged() { |
38 | | - int[] values = {99}; |
39 | | - |
40 | | - ArrayRotation.rotateLeft(values, 5); |
41 | | - |
42 | | - assertArrayEquals(new int[] {99}, values); |
| 31 | + void testForLowerSizeStep() { |
| 32 | + int[] arr = {3, 1, 5, 8, 6}; |
| 33 | + int n = 2; |
| 34 | + int[] expected = {5, 8, 6, 3, 1}; |
| 35 | + int[] result = ArrayLeftRotation.rotateLeft(arr, n); |
| 36 | + assertArrayEquals(expected, result); |
43 | 37 | } |
44 | 38 |
|
45 | 39 | @Test |
46 | | - void shouldHandleEmptyArrayWithoutErrors() { |
47 | | - int[] values = {}; |
48 | | - |
49 | | - ArrayRotation.rotateRight(values, 3); |
50 | | - |
51 | | - assertArrayEquals(new int[] {}, values); |
| 40 | + void testForHigherSizeStep() { |
| 41 | + int[] arr = {3, 1, 5, 8, 6}; |
| 42 | + int n = 7; |
| 43 | + int[] expected = {5, 8, 6, 3, 1}; |
| 44 | + int[] result = ArrayLeftRotation.rotateLeft(arr, n); |
| 45 | + assertArrayEquals(expected, result); |
52 | 46 | } |
53 | 47 |
|
54 | 48 | @Test |
55 | | - void shouldReturnOriginalArrayWhenRotationIsZero() { |
56 | | - int[] values = {7, 8, 9}; |
57 | | - |
58 | | - ArrayRotation.rotateLeft(values, 0); |
59 | | - |
60 | | - assertArrayEquals(new int[] {7, 8, 9}, values); |
| 49 | + void testForEmptyArray() { |
| 50 | + int[] arr = {}; |
| 51 | + int[] result = ArrayLeftRotation.rotateLeft(arr, 3); |
| 52 | + assertArrayEquals(arr, result); |
61 | 53 | } |
62 | 54 | } |
0 commit comments