diff --git a/src/test/java/com/cronutils/mapper/WeekDayTest.java b/src/test/java/com/cronutils/mapper/WeekDayTest.java index b8c6c94a..b642af68 100755 --- a/src/test/java/com/cronutils/mapper/WeekDayTest.java +++ b/src/test/java/com/cronutils/mapper/WeekDayTest.java @@ -65,4 +65,32 @@ public void testMapIntervalWithoutZeroStartingSunday() { final WeekDay target = new WeekDay(2, false); assertEquals(1, source.mapTo(value, target)); } + + @Test + public void testMapSourceWithZeroStartingMonday_TargetWithZeroNotStartingMonday() { + final WeekDay source = new WeekDay(0, true); + final WeekDay target = new WeekDay(1, true); + assertEquals(1, source.mapTo(6, target)); + } + + @Test + public void testMapSourceWithZeroStartingMonday_TargetWithZeroStartingMonday() { + final WeekDay source = new WeekDay(0, true); + final WeekDay target = new WeekDay(0, true); + assertEquals(6, source.mapTo(6, target)); + } + + @Test + public void testMapSourceWithZeroStartingMonday_TargetWithoutZeroStartingMonday() { + final WeekDay source = new WeekDay(0, true); + final WeekDay target = new WeekDay(1, false); + assertEquals(2, source.mapTo(1, target)); + } + + @Test + public void testMapSourceWithZeroStartingMonday_TargetWithoutZeroStartingSunday() { + final WeekDay source = new WeekDay(0, true); + final WeekDay target = new WeekDay(2, false); + assertEquals(2, source.mapTo(6, target)); + } } diff --git a/src/test/java/com/cronutils/model/field/expression/OnTest.java b/src/test/java/com/cronutils/model/field/expression/OnTest.java index 38a0f106..99b79d83 100755 --- a/src/test/java/com/cronutils/model/field/expression/OnTest.java +++ b/src/test/java/com/cronutils/model/field/expression/OnTest.java @@ -80,4 +80,23 @@ public void testAsStringWithNth() { assertEquals(expression, new On(new IntegerFieldValue(first), new SpecialCharFieldValue(SpecialChar.HASH), new IntegerFieldValue(second)).asString()); } + + @Test + public void testAsStringSpecialCharQuestionMark() { + final String expression = "?"; + assertEquals(expression, new On(new SpecialCharFieldValue(SpecialChar.QUESTION_MARK)).asString()); + } + + @Test + public void testAsStringSpecialCharLWithTime() { + final int dayOfWeek = 5; + final String expression = String.format("%sL", dayOfWeek); + assertEquals(expression, new On(new IntegerFieldValue(dayOfWeek), new SpecialCharFieldValue(SpecialChar.L)).asString()); + } + + @Test + public void testAsStringSpecialCharWDefault() { + final String expression = "W"; + assertEquals(expression, new On(new IntegerFieldValue(-1), new SpecialCharFieldValue(SpecialChar.W)).asString()); + } } diff --git a/src/test/java/com/cronutils/model/time/TimeNodeTest.java b/src/test/java/com/cronutils/model/time/TimeNodeTest.java index b1dca13d..52c1c284 100755 --- a/src/test/java/com/cronutils/model/time/TimeNodeTest.java +++ b/src/test/java/com/cronutils/model/time/TimeNodeTest.java @@ -103,6 +103,37 @@ public void testGetValueFromListWithEmptyList() { assertThrows(IllegalArgumentException.class, () -> timeNode.getValueFromList(new ArrayList<>(), 0, new AtomicInteger(0))); } + @Test + public void testGetValueFromListWithLargeIndices() { + final List values = Arrays.asList(2, 8, 14, 20); + final AtomicInteger shift = new AtomicInteger(0); + + final int largePositiveIndex = 365 * 6; + int value = timeNode.getValueFromList(values, largePositiveIndex, shift); + assertEquals(14, value); + assertEquals(547, shift.get()); + + shift.set(0); + final int largeNegativeIndex = -1000; + value = timeNode.getValueFromList(values, largeNegativeIndex, shift); + assertEquals(2, value); + assertEquals(250, shift.get()); + } + + @Test + public void testGetValueFromListWithDuplicates() { + final List tradingTimes = Arrays.asList(930, 930, 1130, 1130, 1300, 1500); + final AtomicInteger shift = new AtomicInteger(0); + int nextSession = timeNode.getValueFromList(tradingTimes, 10, shift); + assertEquals(1300, nextSession); + assertEquals(1, shift.get()); + + shift.set(0); + int prevSession = timeNode.getValueFromList(tradingTimes, -5, shift); + assertEquals(930, prevSession); + assertEquals(1, shift.get()); + } + private void assertResult(final int value, final int shift, final NearestValue nearestValue) { assertEquals(value, nearestValue.getValue(), String.format("Values do not match! Expected: %s Found: %s", value, nearestValue.getValue())); assertEquals(shift, nearestValue.getShifts(), String.format("Shifts do not match! Expected: %s Found: %s", shift, nearestValue.getShifts()));