File: t5880.scala

package info (click to toggle)
scala 2.11.12-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 62,776 kB
  • sloc: java: 13,415; xml: 3,252; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (41 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (4)
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


import scala.collection.JavaConversions._



object Test {

  def main(args:Array[String]) = {
    val tests = 5000
    val jm: java.util.Map[Int, Int] = scala.collection.mutable.Map((0 until tests) zip (0 until tests).reverse: _*)
    val es = jm.entrySet()
    val it = es.iterator

    // chi square test
    val groups = 10
    val hits = new Array[Int](groups)
    def hit(hc: Int) {
      val bucket = math.abs(hc) / (Int.MaxValue / groups)
      hits(bucket) += 1
    }
    def expected = tests / groups
    def Dstat = {
      val diffs = for (i <- 0 until groups) yield math.abs(hits(i) - expected)
      diffs.sum.toDouble / expected
    }
    def ChiSquare = {
      val diffs = for (i <- 0 until groups) yield (hits(i) - expected) * (hits(i) - expected)
      diffs.sum.toDouble / expected
    }

    while (it.hasNext) {
      val x = it.next()
      hit(x.##)
    }
    // println(hits.toBuffer)
    // println(ChiSquare)
    assert(ChiSquare < 4.0, ChiSquare + " -> " + hits.mkString(", "))
  }

}