diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2016-06-02 15:37:16 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan@lightbend.com> | 2016-06-02 15:37:16 -0700 |
commit | 3cbe3e89264ad63c9b86ea4962da553a24bfb128 (patch) | |
tree | b2412013a1ac5453c7a0f63e6ffb21ab7013bd63 /test/junit | |
parent | 25165b7ad9c4aafdddb4e871b195a91014a91b72 (diff) | |
parent | 7952cd1651b6ed1fe0cd68198e49cf90423242d8 (diff) | |
download | scala-3cbe3e89264ad63c9b86ea4962da553a24bfb128.tar.gz scala-3cbe3e89264ad63c9b86ea4962da553a24bfb128.tar.bz2 scala-3cbe3e89264ad63c9b86ea4962da553a24bfb128.zip |
Merge pull request #5207 from lrytz/nan-compare
Fix comparisons involving NaN
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/lang/primitives/NaNTest.scala | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/junit/scala/lang/primitives/NaNTest.scala b/test/junit/scala/lang/primitives/NaNTest.scala new file mode 100644 index 0000000000..f4c4258395 --- /dev/null +++ b/test/junit/scala/lang/primitives/NaNTest.scala @@ -0,0 +1,38 @@ +package scala.lang.primitives + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +import scala.tools.testing.RunTesting + +@RunWith(classOf[JUnit4]) +class NaNTest extends RunTesting { + + @Test + def compNaNFalse(): Unit = { + def code(tp: String) = + s"""val n = $tp.NaN + |def ne(x: $tp, y: $tp) = x != y + |val fs: List[($tp, $tp) => Boolean] = List(_ < _, _ <= _, _ > _, _ >= _, _ == _, (x, y) => !ne(x, y)) + |val vs = List[$tp](n, 1, -1, 0) + |for (f <- fs; v <- vs; (x, y) <- List((n, v), (v, n))) yield f(x, y) + """.stripMargin + + runner.run[List[Boolean]](code("Double")).foreach(assertFalse) + runner.run[List[Boolean]](code("Float")).foreach(assertFalse) + } + + @Test + def genericEqNe(): Unit = { + def code(tp: String) = + s"""def a[T](x: T, y: T) = x == y + |def b[T](x: T, y: T) = x != y + |val n = $tp.NaN + |a(n, n) :: a(n, 0) :: a (0, n) :: !b(n, n) :: !b(n, 0) :: !b(0, n) :: Nil + """.stripMargin + runner.run[List[Boolean]](code("Double")).foreach(assertFalse) + runner.run[List[Boolean]](code("Float")).foreach(assertFalse) + } +} |