Skip to content

Commit

Permalink
Added And Modified Unit Tests
Browse files Browse the repository at this point in the history
Signed-off-by: GabeFernandez310 <Gabriel.Fernandez@improving.com>
  • Loading branch information
GabeFernandez310 committed Mar 6, 2023
1 parent 5ee1687 commit f5c480c
Showing 1 changed file with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ private void yearweekQuery(String date, int mode, int expectedResult) {
.yearweek(
functionProperties,
DSL.literal(new ExprDateValue(date)), DSL.literal(mode));
assertEquals(INTEGER, expression.type());
assertEquals(String.format("yearweek(DATE '%s', %d)", date, mode), expression.toString());
assertEquals(integerValue(expectedResult), eval(expression));
assertAll(
() -> assertEquals(INTEGER, expression.type()),
() -> assertEquals(
String.format("yearweek(DATE '%s', %d)", date, mode), expression.toString()),
() -> assertEquals(integerValue(expectedResult), eval(expression))
);
}

private static Stream<Arguments> getTestDataForYearweek() {
Expand Down Expand Up @@ -76,12 +79,29 @@ private static Stream<Arguments> getTestDataForYearweek() {

@ParameterizedTest(name = "{0} | {1}")
@MethodSource("getTestDataForYearweek")
public void testWeekyear(String date, int mode, int expected) {
public void testYearweak(String date, int mode, int expected) {
yearweekQuery(date, mode, expected);
}

@Test
public void testYearWeekWithTimeType() {
public void testYearweekWithoutMode() {
LocalDate date = LocalDate.of(2019,1,05);

FunctionExpression expression = DSL
.yearweek(
functionProperties,
DSL.literal(new ExprDateValue(date)), DSL.literal(0));

FunctionExpression expressionWithoutMode = DSL
.yearweek(
functionProperties,
DSL.literal(new ExprDateValue(date)), DSL.literal(0));

assertEquals(eval(expression), eval(expressionWithoutMode));
}

@Test
public void testYearweekWithTimeType() {
int week = LocalDate.now(functionProperties.getQueryStartClock()).get(ALIGNED_WEEK_OF_YEAR);
int year = LocalDate.now(functionProperties.getQueryStartClock()).getYear();
int expected = Integer.parseInt(String.format("%d%02d", year, week));
Expand All @@ -91,7 +111,15 @@ public void testYearWeekWithTimeType() {
functionProperties,
DSL.literal(new ExprTimeValue("10:11:12")), DSL.literal(0));

assertEquals(expected, eval(expression).integerValue());
FunctionExpression expressionWithoutMode = DSL
.yearweek(
functionProperties,
DSL.literal(new ExprTimeValue("10:11:12")));

assertAll(
() -> assertEquals(expected, eval(expression).integerValue()),
() -> assertEquals(expected, eval(expressionWithoutMode).integerValue())
);
}

@Test
Expand Down

0 comments on commit f5c480c

Please sign in to comment.