diff options
author | Hao Huang <hhuang@driver.xyz> | 2017-02-10 16:17:01 -0800 |
---|---|---|
committer | Hao Huang <hhuang@driver.xyz> | 2017-02-10 16:17:01 -0800 |
commit | 1e65b8ad5967d41dc56d7dce015f4bb6c1af26dd (patch) | |
tree | 84221982bcbca6dd461364c865f1cb1273fd62c1 /src/test | |
parent | 4adc14f77762f48436f3c56f9328a6e4bedfe824 (diff) | |
download | driver-core-1e65b8ad5967d41dc56d7dce015f4bb6c1af26dd.tar.gz driver-core-1e65b8ad5967d41dc56d7dce015f4bb6c1af26dd.tar.bz2 driver-core-1e65b8ad5967d41dc56d7dce015f4bb6c1af26dd.zip |
Add the companion ordering object for Date
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/scala/xyz/driver/core/DateTest.scala | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/core/DateTest.scala b/src/test/scala/xyz/driver/core/DateTest.scala new file mode 100644 index 0000000..50f8521 --- /dev/null +++ b/src/test/scala/xyz/driver/core/DateTest.scala @@ -0,0 +1,41 @@ +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.tagMonth(month), day) + implicit val arbitraryDate = Arbitrary[Date](dateGenerator) + + 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 + } + } + } + } +} |