|
Scala example source code file (primitive-eqeq.scala)
The Scala primitive-eqeq.scala source codeimport org.scalacheck._ import Prop._ import Gen._ object Test extends Properties("==") { def equalObjectsEqualHashcodes(x: Any, y: Any) = (x != y) || (x == y && x.## == y.##) // ticket #2087 property("short/char") = forAll { (x: Short) => { val ch: Char = x.toChar (x == ch) == (ch == x) } } property("symmetry") = forAll { (x: AnyVal, y: AnyVal) => (x == y) == (y == x) } property("transitivity") = forAll { (x: AnyVal, y: AnyVal, z: AnyVal) => x != y || y != z || x == z } property("##") = forAll { (x: Short) => { val anyvals = List(x.toByte, x.toChar, x, x.toInt, x.toLong, x.toFloat, x.toDouble, BigInt(x), BigDecimal(x)) val shortAndLarger = anyvals drop 2 val result = ( ((anyvals, anyvals).zipped forall equalObjectsEqualHashcodes) && ((shortAndLarger, shortAndLarger).zipped forall (_ == _)) && ((shortAndLarger, shortAndLarger).zipped forall ((x, y) => (x: Any) == (y: Any))) ) result } } property("## 2") = forAll { (dv: Double) => { val fv = dv.toFloat (fv != dv) || (fv.## == dv.##) } } } Other Scala examples (source code examples)Here is a short list of links related to this Scala primitive-eqeq.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.