scala - Assertion for overloaded equality operator fails for triple-equals but passes for double-equals -


i overloaded case class's equality operator:

case class polygon(points: seq[(double, double)]) extends shape {   def ==(that: polygon): boolean = { ... } } 

my unit tests pass when using double-equals in assertions:

import org.scalatest.funspec  class shapespec extends funspec {   describe("polygon") {     it("is equal rotations") {       val p = polygon(seq( ... ))       { ← 0 until p.points.size } {         val q = polygon(p.points.drop(i) ++ p.points.take(i))         assert(p == q)       }     }   } } 

but when using === instead of ==, same tests fail:

[info] polygon [info] - equal rotations *** failed *** [info]   polygon(list((-1.0,-1.0), (4.0,-1.0), (4.0,2.0), (1.0,2.0),          (1.0,1.0), (-1.0,1.0))) did not equal polygonm(list((4.0,-1.0),          (4.0,2.0), (1.0,2.0), (1.0,1.0), (-1.0,1.0), (-1.0,-1.0)))          (shapespec.scala:28) 

why happen?

you spelled wrong. ;)

it should be:

override def equals(x: any): boolean 

Popular posts from this blog