Skip to content

Commit a5d56c3

Browse files
committed
Add more tests to RotateLinkedList. Adjust regex for ValidNumber solution
1 parent e0b84eb commit a5d56c3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/by/andd3dfx/numeric/ValidNumber.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
public class ValidNumber {
3333

3434
public static boolean isNumber(String s) {
35-
return s.matches("(\\+|-)?([0-9]+\\.?([0-9]+)?|\\.[0-9]+)((e|E)(\\+|-)?[0-9]+)?");
35+
return s.matches("(\\+|-)?(\\d+\\.?(\\d+)?|\\.\\d+)((e|E)(\\+|-)?\\d+)?");
3636
}
3737
}

src/test/java/by/andd3dfx/collections/RotateLinkedListTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,27 @@ public void testRotateRight_whenJustShiftNeeded2() {
2727
checkLinkedListContent(result2, new int[]{2, 1});
2828
}
2929

30+
@Test
31+
public void testRotateRight_whenJustBackwardShiftNeeded() {
32+
var result = rotateRight(buildLinkedList(new int[]{1, 2, 3, 4, 5}), -2);
33+
34+
checkLinkedListContent(result, new int[]{3, 4, 5, 1, 2});
35+
}
36+
3037
@Test
3138
public void testRotateRight_whenShiftGreaterThanArraySize() {
3239
var result = rotateRight(buildLinkedList(new int[]{0, 1, 2}), 4);
3340

3441
checkLinkedListContent(result, new int[]{2, 0, 1});
3542
}
3643

44+
@Test
45+
public void testRotateRight_whenBackwardShiftGreaterThanArraySize() {
46+
var result = rotateRight(buildLinkedList(new int[]{0, 1, 2}), -4);
47+
48+
checkLinkedListContent(result, new int[]{1, 2, 0});
49+
}
50+
3751
@Test
3852
public void testRotateRight_whenShiftGreaterThanArraySizeButEqualsToIntAmountOfSizes() {
3953
var result = rotateRight(buildLinkedList(new int[]{0, 1, 2}), 6);

0 commit comments

Comments
 (0)