summaryrefslogtreecommitdiff
path: root/test/files/run/hashCodeDistribution.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-11-04 06:36:03 +0000
committerPaul Phillips <paulp@improving.org>2009-11-04 06:36:03 +0000
commitf5ede0923cd8dd2d45853a06e71e05052e462213 (patch)
tree731d9f9314e9a1762dd9f513cce15dff8b231829 /test/files/run/hashCodeDistribution.scala
parentb02b388ffaa5ea6d62669bb91d8af6de521aa71f (diff)
downloadscala-f5ede0923cd8dd2d45853a06e71e05052e462213.tar.gz
scala-f5ede0923cd8dd2d45853a06e71e05052e462213.tar.bz2
scala-f5ede0923cd8dd2d45853a06e71e05052e462213.zip
Scala implementation of fancier hashCode algori...
Scala implementation of fancier hashCode algorithm. At the moment it isn't used unless you supply -Yjenkins-hashCodes to scalac. Without the flag, the supplied test case generates 12559 unique hashCodes among 90000 case class instances; with the flag it generates 89999.
Diffstat (limited to 'test/files/run/hashCodeDistribution.scala')
-rw-r--r--test/files/run/hashCodeDistribution.scala17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/files/run/hashCodeDistribution.scala b/test/files/run/hashCodeDistribution.scala
new file mode 100644
index 0000000000..dbb6e833bd
--- /dev/null
+++ b/test/files/run/hashCodeDistribution.scala
@@ -0,0 +1,17 @@
+// See ticket #2537.
+object Test {
+ case class C(x: Int, y: Int) { }
+ val COUNT = 300
+ val totalCodes = COUNT * COUNT
+
+ def main (args: Array[String]) = {
+ val hashCodes =
+ for (x <- 0 until COUNT; y <- 0 until COUNT) yield C(x,y).hashCode
+
+ val uniques = hashCodes.removeDuplicates
+ val collisionRate = (totalCodes - uniques.size) * 1000 / totalCodes
+
+ assert(collisionRate < 5, "Collision rate too high: %d / 1000".format(collisionRate))
+ // println("collisionRate = %d / 1000".format(collisionRate))
+ }
+} \ No newline at end of file