summaryrefslogtreecommitdiff
path: root/test/files/jvm
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-09-19 09:25:33 -0700
committerPaul Phillips <paulp@improving.org>2012-09-19 09:57:32 -0700
commit68c0e596549765a15474b56ab9013ed3ba53b0ce (patch)
tree913dcfc76435b763a930c927e9c16e3f9737fc63 /test/files/jvm
parent0ae9142bbee3e12f684d1af9a7e28ca795ba9f4f (diff)
downloadscala-68c0e596549765a15474b56ab9013ed3ba53b0ce.tar.gz
scala-68c0e596549765a15474b56ab9013ed3ba53b0ce.tar.bz2
scala-68c0e596549765a15474b56ab9013ed3ba53b0ce.zip
Adjustments to scala.concurrent.duration.
More use of implicit classes and value classes; aliased units to make importing TimeUnit and TimeUnit._ unnecessary; placed some classes in their own files because "the unit of compilation is the file" and we shouldn't bundle more than necessary; fixed some examples.
Diffstat (limited to 'test/files/jvm')
-rw-r--r--test/files/jvm/duration-tck.scala19
1 files changed, 9 insertions, 10 deletions
diff --git a/test/files/jvm/duration-tck.scala b/test/files/jvm/duration-tck.scala
index 1a09007dc9..40073c0b3f 100644
--- a/test/files/jvm/duration-tck.scala
+++ b/test/files/jvm/duration-tck.scala
@@ -1,10 +1,9 @@
/**
* Copyright (C) 2012 Typesafe Inc. <http://www.typesafe.com>
*/
-
+
import scala.concurrent.duration._
import scala.reflect._
-import java.util.concurrent.TimeUnit._
import scala.tools.partest.TestUtil.intercept
object Test extends App {
@@ -38,7 +37,7 @@ object Test extends App {
two / one mustBe 2
one + zero mustBe one
one / 1000000 mustBe 1.micro
-
+
// test infinities
@@ -90,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
@@ -121,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)) {
@@ -152,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
@@ -183,10 +182,10 @@ object Test extends App {
(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 * 2 / 3 mul 5 div 4 plus 3.seconds minus 1.millisecond min 1.second max 1.second
-
+
}