Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/test/java/com/cronutils/mapper/WeekDayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/cronutils/model/field/expression/OnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
31 changes: 31 additions & 0 deletions src/test/java/com/cronutils/model/time/TimeNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,37 @@ public void testGetValueFromListWithEmptyList() {
assertThrows(IllegalArgumentException.class, () -> timeNode.getValueFromList(new ArrayList<>(), 0, new AtomicInteger(0)));
}

@Test
public void testGetValueFromListWithLargeIndices() {
final List<Integer> 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<Integer> 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()));
Expand Down