Repository navigation
Expand file tree
/
Copy pathArrayRotationTest.java
More file actions
80 lines (53 loc) · 1.82 KB
/
Copy pathArrayRotationTest.java
File metadata and controls
80 lines (53 loc) · 1.82 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.thealgorithms.others;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.jupiter.api.Test;
public class ArrayRotationTest {
@Test
void shouldRotateArrayRightByTwoPositions() {
int[] values = {1, 2, 3, 4, 5};
ArrayRotation.rotateRight(values, 2);
assertArrayEquals(new int[] {4, 5, 1, 2, 3}, values);
}
@Test
void shouldRotateArrayLeftByTwoPositions() {
int[] values = {1, 2, 3, 4, 5};
ArrayRotation.rotateLeft(values, 2);
assertArrayEquals(new int[] {3, 4, 5, 1, 2}, values);
}
@Test
void shouldHandleRotationGreaterThanArrayLength() {
int[] values = {10, 20, 30, 40};
ArrayRotation.rotateRight(values, 6);
assertArrayEquals(new int[] {30, 40, 10, 20}, values);
}
@Test
void shouldHandleLeftRotationGreaterThanArrayLength() {
int[] values = {10, 20, 30, 40};
ArrayRotation.rotateLeft(values, 6);
assertArrayEquals(new int[] {30, 40, 10, 20}, values);
}
@Test
void shouldKeepSingleElementArrayUnchanged() {
int[] values = {99};
ArrayRotation.rotateLeft(values, 5);
assertArrayEquals(new int[] {99}, values);
}
@Test
void shouldHandleEmptyArrayWithoutErrors() {
int[] values = {};
ArrayRotation.rotateRight(values, 3);
assertArrayEquals(new int[] {}, values);
}
@Test
void shouldReturnOriginalArrayWhenRotationIsZero() {
int[] values = {7, 8, 9};
ArrayRotation.rotateLeft(values, 0);
assertArrayEquals(new int[] {7, 8, 9}, values);
}
@Test
void shouldHandleNegativeRotation() {
int[] values = {1, 2, 3, 4, 5};
ArrayRotation.rotateRight(values, -2);
assertArrayEquals(new int[] {3, 4, 5, 1, 2}, values);
}
}