aboutsummaryrefslogtreecommitdiff
path: root/tests/run/t5857.scala
blob: fe67a75465a4d9885e9aed6130d54e0d1eb9c674 (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
39
40
41
42
43
44
object Test {

  def time[U](b: =>U): Long = {
    val start = System.currentTimeMillis
    b
    val end = System.currentTimeMillis

    end - start
  }

  def main(args: Array[String]): Unit = {
    val sz = 1000000000

    val range = 1 to sz
    check { assert(range.min == 1, range.min) }
    check { assert(range.max == sz, range.max) }

    val descending = sz to 1 by -1
    check { assert(descending.min == 1) }
    check { assert(descending.max == sz) }

    val numeric = 1.0 to sz.toDouble by 1
    check { assert(numeric.min == 1.0) }
    check { assert(numeric.max == sz.toDouble) }

    val numdesc = sz.toDouble to 1.0 by -1
    check { assert(numdesc.min == 1.0) }
    check { assert(numdesc.max == sz.toDouble) }
  }

  def check[U](b: =>U): Unit = {
    val exectime = time {
      b
    }

    // whatever it is, it should be less than, say, 1000ms
    // if `max` involves traversal, it takes over 5 seconds on a 3.2GHz i7 CPU
    //println(exectime)
    assert(exectime < 1000, exectime)
  }
}