Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
GoodaCheeze
Java
Repository navigation
Code
Pull requests
1
(1)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Java
/
src
/
test
/
java
/
com
/
thealgorithms
/
searches
/
HowManyTimesRotatedTest.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
34 lines (28 loc) · 1.23 KB
master
Breadcrumbs
Java
/
src
/
test
/
java
/
com
/
thealgorithms
/
searches
/
HowManyTimesRotatedTest.java
Copy path
Top
File metadata and controls
Code
Blame
34 lines (28 loc) · 1.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package com.thealgorithms.searches;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
public class HowManyTimesRotatedTest {
@Test
public void testHowManyTimesRotated() {
int[] arr1 = {5, 1, 2, 3, 4};
assertEquals(1, HowManyTimesRotated.rotated(arr1));
int[] arr2 = {15, 17, 2, 3, 5};
assertEquals(2, HowManyTimesRotated.rotated(arr2));
}
/** An unrotated (already sorted) array should resolve to 0 rotations without hanging. */
@Test
@Timeout(value = 5, unit = TimeUnit.SECONDS, threadMode = Timeout.ThreadMode.SEPARATE_THREAD)
public void testHowManyTimesRotatedOnUnrotatedArray() {
int[] arr = {2, 5, 6, 8, 11, 12, 15, 18};
assertEquals(0, HowManyTimesRotated.rotated(arr));
}
/** Arrays of size 1 and 2 should not throw ArrayIndexOutOfBoundsException. */
@Test
public void testHowManyTimesRotatedOnSmallArrays() {
assertEquals(0, HowManyTimesRotated.rotated(new int[] {5}));
assertEquals(0, HowManyTimesRotated.rotated(new int[] {1, 2}));
assertEquals(1, HowManyTimesRotated.rotated(new int[] {2, 1}));
}
}
You can’t perform that action at this time.