Skip to content

Commit

Permalink
test: Verify normalized string format of duration
Browse files Browse the repository at this point in the history
Add test cases to verify that a duration returns a normalized value.
  • Loading branch information
saig0 committed Jan 17, 2025
1 parent 61a5064 commit bb287f0
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class StringRepresentationTypeTest extends AnyFlatSpec with Matchers {
duration.toString should be("P2M")
}

it should "return normalized format " in {
ValYearMonthDuration(Period.parse("P2Y")).toString should be("P2Y")
ValYearMonthDuration(Period.parse("P24M")).toString should be("P2Y")

ValYearMonthDuration(Period.parse("P25M")).toString should be("P2Y1M")
ValYearMonthDuration(Period.parse("P35M")).toString should be("P2Y11M")
}

"A days-time-duration" should "return 'P1DT2H3M4S' " in {
val duration = ValDayTimeDuration(Duration.parse("P1DT2H3M4S"))

Expand Down Expand Up @@ -151,6 +159,17 @@ class StringRepresentationTypeTest extends AnyFlatSpec with Matchers {
duration.toString should be("PT4S")
}

it should "return normalized format " in {
ValDayTimeDuration(Duration.parse("P5D")).toString should be("P5D")
ValDayTimeDuration(Duration.parse("PT120H")).toString should be("P5D")
ValDayTimeDuration(Duration.parse("PT7200M")).toString should be("P5D")
ValDayTimeDuration(Duration.parse("PT432000S")).toString should be("P5D")

ValDayTimeDuration(Duration.parse("PT121H")).toString should be("P5DT1H")
ValDayTimeDuration(Duration.parse("PT7201M")).toString should be("P5DT1M")
ValDayTimeDuration(Duration.parse("PT7261M")).toString should be("P5DT1H1M")
}

"A list" should "return '[1, 2]' " in {
ValList(List(ValNumber(1), ValNumber(2))).toString should be("[1, 2]")
}
Expand Down

0 comments on commit bb287f0

Please sign in to comment.