summaryrefslogtreecommitdiff
path: root/test/files/scalacheck/eqeq.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/scalacheck/eqeq.scala')
-rw-r--r--test/files/scalacheck/eqeq.scala32
1 files changed, 26 insertions, 6 deletions
diff --git a/test/files/scalacheck/eqeq.scala b/test/files/scalacheck/eqeq.scala
index 163f17d94c..60fe63c207 100644
--- a/test/files/scalacheck/eqeq.scala
+++ b/test/files/scalacheck/eqeq.scala
@@ -3,15 +3,35 @@ import Prop._
import Gen._
object Test extends Properties("==") {
- property("reflexive") = forAll { (x: AnyVal, y: AnyVal) => (x == y) == (y == x) }
- // property("hashCode") = forAll { (x
+ 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) ||
- // that's the whole test once it works, but since it doesn't yet:
- x < 0
+ (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.##)
+ }
+ }
+}