aboutsummaryrefslogtreecommitdiff
path: root/core-types/src/test/scala/xyz/driver/core/DateTest.scala
diff options
context:
space:
mode:
authorJakob Odersky <jakob@driver.xyz>2018-09-12 15:56:41 -0700
committerJakob Odersky <jakob@odersky.com>2018-10-09 16:19:39 -0700
commit7a793ffa068fda8f2146f84fa785328d928dba03 (patch)
treed489b0b9ebf30ca61e2b6ef1c9906b704bc1fa1e /core-types/src/test/scala/xyz/driver/core/DateTest.scala
parent2cef01adfe3ebd3a0fa1e0bbbba7f6388198ba10 (diff)
downloaddriver-core-7a793ffa068fda8f2146f84fa785328d928dba03.tar.gz
driver-core-7a793ffa068fda8f2146f84fa785328d928dba03.tar.bz2
driver-core-7a793ffa068fda8f2146f84fa785328d928dba03.zip
Move core types into core-types project
Note that xyz.driver.core.FutureExtensions was moved to xyz.driver.core.rest as it (only) contained logic that dealt with service exceptions, something that belongs into core-rest and must not be depended upon by core-types. This is a breaking change.
Diffstat (limited to 'core-types/src/test/scala/xyz/driver/core/DateTest.scala')
-rw-r--r--core-types/src/test/scala/xyz/driver/core/DateTest.scala53
1 files changed, 53 insertions, 0 deletions
diff --git a/core-types/src/test/scala/xyz/driver/core/DateTest.scala b/core-types/src/test/scala/xyz/driver/core/DateTest.scala
new file mode 100644
index 0000000..0432040
--- /dev/null
+++ b/core-types/src/test/scala/xyz/driver/core/DateTest.scala
@@ -0,0 +1,53 @@
+package xyz.driver.core
+
+import org.scalacheck.{Arbitrary, Gen}
+import org.scalatest.prop.Checkers
+import org.scalatest.{FlatSpec, Matchers}
+import xyz.driver.core.date.Date
+
+class DateTest extends FlatSpec with Matchers with Checkers {
+ val dateGenerator = for {
+ year <- Gen.choose(0, 3000)
+ month <- Gen.choose(0, 11)
+ day <- Gen.choose(1, 31)
+ } yield Date(year, date.Month(month), day)
+ implicit val arbitraryDate = Arbitrary[Date](dateGenerator)
+
+ "Date" should "correctly convert to and from String" in {
+
+ import xyz.driver.core.generators.nextDate
+ import date._
+
+ for (date <- 1 to 100 map (_ => nextDate())) {
+ Some(date) should be(Date.fromString(date.toString))
+ }
+ }
+
+ it should "have ordering defined correctly" in {
+ Seq(
+ Date.fromString("2013-05-10"),
+ Date.fromString("2020-02-15"),
+ Date.fromString("2017-03-05"),
+ Date.fromString("2013-05-12")).sorted should
+ contain theSameElementsInOrderAs Seq(
+ Date.fromString("2013-05-10"),
+ Date.fromString("2013-05-12"),
+ Date.fromString("2017-03-05"),
+ Date.fromString("2020-02-15"))
+
+ check { dates: List[Date] =>
+ dates.sorted.sliding(2).filter(_.size == 2).forall {
+ case Seq(a, b) =>
+ if (a.year == b.year) {
+ if (a.month == b.month) {
+ a.day <= b.day
+ } else {
+ a.month < b.month
+ }
+ } else {
+ a.year < b.year
+ }
+ }
+ }
+ }
+}