diff options
author | vlad <vlad@drivergrp.com> | 2016-07-19 15:01:30 -0400 |
---|---|---|
committer | vlad <vlad@drivergrp.com> | 2016-07-19 15:01:30 -0400 |
commit | 979ff9e765e3c08501cbd00354a87013853fe796 (patch) | |
tree | c5d41ed99759c3bf97ba4ef9162aeb68ed4c29f8 /src/test/scala/com/drivergrp/core/TimeTest.scala | |
parent | 8d45c2ec5e8abc63046c610109471cc3fa7bfaa2 (diff) | |
download | driver-core-979ff9e765e3c08501cbd00354a87013853fe796.tar.gz driver-core-979ff9e765e3c08501cbd00354a87013853fe796.tar.bz2 driver-core-979ff9e765e3c08501cbd00354a87013853fe796.zip |
Unit tests for core code and bug fixes
Diffstat (limited to 'src/test/scala/com/drivergrp/core/TimeTest.scala')
-rw-r--r-- | src/test/scala/com/drivergrp/core/TimeTest.scala | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/test/scala/com/drivergrp/core/TimeTest.scala b/src/test/scala/com/drivergrp/core/TimeTest.scala new file mode 100644 index 0000000..ad390c8 --- /dev/null +++ b/src/test/scala/com/drivergrp/core/TimeTest.scala @@ -0,0 +1,57 @@ +package com.drivergrp.core + +import com.drivergrp.core.time.{Time, _} +import org.scalatest.{FlatSpec, Matchers} + +import scala.concurrent.duration._ + +class TimeTest extends FlatSpec with Matchers { + + "Time" should "have correct methods to compare" in { + + Time(234L).isAfter(Time(123L)) should be(true) + Time(123L).isAfter(Time(123L)) should be(false) + Time(123L).isAfter(Time(234L)) should be(false) + + Time(234L).isBefore(Time(123L)) should be(false) + Time(123L).isBefore(Time(123L)) should be(false) + Time(123L).isBefore(Time(234L)) should be(true) + } + + it should "not modify time" in { + + Time(234L).millis should be(234L) + } + + it should "support arithmetic with scala.concurrent.duration" in { + + Time(123L).advanceBy(0 minutes).millis should be(123L) + Time(123L).advanceBy(1 second).millis should be(123L + Second) + Time(123L).advanceBy(4 days).millis should be(123L + 4 * Days) + } + + it should "have ordering defined correctly" in { + + Seq(Time(321L), Time(123L), Time(231L)).sorted should + contain theSameElementsInOrderAs Seq(Time(123L), Time(231L), Time(321L)) + } + + it should "reset to the start of the period, e.g. month" in { + + startOfMonth(Time(1468937089834L)) should be(Time(1467381889834L)) + startOfMonth(Time(1467381889834L)) should be(Time(1467381889834L)) // idempotent + } + + it should "have correct textual representations" in { + + textualDate(Time(1468937089834L)) should be("July 19, 2016") + textualTime(Time(1468937089834L)) should be("Jul 19, 2016 10:04:49 AM") + } + + "TimeRange" should "have duration defined as a difference of start and end times" in { + + TimeRange(Time(321L), Time(432L)).duration should be(111.milliseconds) + TimeRange(Time(432L), Time(321L)).duration should be((-111).milliseconds) + TimeRange(Time(333L), Time(333L)).duration should be(0.milliseconds) + } +} |