summaryrefslogtreecommitdiff
path: root/test/junit/scala/lang/primitives/NaNTest.scala
blob: f4c42583952e02f5a094a199c2e69f32562b182d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)
  }
}