diff options
author | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-20 10:22:01 -0700 |
---|---|---|
committer | Josh Suereth <Joshua.Suereth@gmail.com> | 2012-09-20 10:22:01 -0700 |
commit | 45c0b2428219b6a00514e21529650b32631880b6 (patch) | |
tree | 88eeb6ce02a1ec9dda21e77f7add4a995a8b9879 /test/files/jvm/duration-tck.scala | |
parent | 1fc89420688d2123615e89a15e515c801729be5a (diff) | |
parent | 05367235ef4c519521cb28073f951e3d55fe3aad (diff) | |
download | scala-45c0b2428219b6a00514e21529650b32631880b6.tar.gz scala-45c0b2428219b6a00514e21529650b32631880b6.tar.bz2 scala-45c0b2428219b6a00514e21529650b32631880b6.zip |
Merge pull request #1339 from rkuhn/wip-6389-finite-duration-mult
enable integer multiplication/divison on FiniteDuration, see SI-6389
Diffstat (limited to 'test/files/jvm/duration-tck.scala')
-rw-r--r-- | test/files/jvm/duration-tck.scala | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/test/files/jvm/duration-tck.scala b/test/files/jvm/duration-tck.scala index 0947e84004..df1052fed3 100644 --- a/test/files/jvm/duration-tck.scala +++ b/test/files/jvm/duration-tck.scala @@ -1,11 +1,9 @@ /** * Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com> */ - -import scala.concurrent.util._ -import duration._ + +import scala.concurrent.duration._ import scala.reflect._ -import java.util.concurrent.TimeUnit._ import scala.tools.partest.TestUtil.intercept object Test extends App { @@ -39,7 +37,7 @@ object Test extends App { two / one mustBe 2 one + zero mustBe one one / 1000000 mustBe 1.micro - + // test infinities @@ -91,7 +89,7 @@ object Test extends App { minf.toUnit(MINUTES) mustBe Double.NegativeInfinity Duration.fromNanos(Double.PositiveInfinity) mustBe inf Duration.fromNanos(Double.NegativeInfinity) mustBe minf - + // test undefined & NaN @@ -122,7 +120,7 @@ object Test extends App { undef.toUnit(DAYS) mustBe nan Duration.fromNanos(nan) mustBe undef - + // test overflow protection for (unit ← Seq(DAYS, HOURS, MINUTES, SECONDS, MILLISECONDS, MICROSECONDS, NANOSECONDS)) { @@ -153,21 +151,21 @@ object Test extends App { } intercept[IllegalArgumentException] { Duration.fromNanos(1e20) } intercept[IllegalArgumentException] { Duration.fromNanos(-1e20) } - + // test precision 1.second + 1.millisecond mustBe 1001.milliseconds 100000.days + 1.nanosecond mustBe 8640000000000000001L.nanoseconds 1.5.seconds.toSeconds mustBe 1 (-1.5).seconds.toSeconds mustBe -1 - + // test unit stability 1000.millis.unit mustBe MILLISECONDS (1000.millis + 0.days).unit mustBe MILLISECONDS 1.second.unit mustBe SECONDS (1.second + 1.millisecond).unit mustBe MILLISECONDS - + // test Deadline val dead = 2.seconds.fromNow @@ -177,10 +175,20 @@ object Test extends App { Thread.sleep(1.second.toMillis) assert(dead.timeLeft < 1.second) assert(dead2.timeLeft < 1.second) - + + + // test integer mul/div + 500.millis * 2 mustBe 1.second + (500.millis * 2).unit mustBe MILLISECONDS + 1.second / 2 mustBe 500.millis + (1.second / 2).unit mustBe MILLISECONDS + // check statically retaining finite-ness - val finiteDuration: FiniteDuration = 1.second plus 3.seconds minus 1.millisecond min 1.second max 1.second - + val finiteDuration: FiniteDuration = 1.second * 2 / 3 mul 5 div 4 plus 3.seconds minus 1.millisecond min 1.second max 1.second + val finite2: FiniteDuration = 2 * 1.second + 3L * 2.seconds + finite2 mustBe 8.seconds + ((2 seconds fromNow).timeLeft: FiniteDuration) < 4.seconds mustBe true + val finite3: FiniteDuration = 3.5 seconds span } |