0

I ran my test, which failed, but for the following (seemingly-contradictory) reason:

should return an myClassVector *** FAILED ***
[info]   Expected myClassVector(3, 9, 12), but got myClassVector(3, 9, 12)

Here is my actual test:

 class myClassVector extends FlatSpec
{
     "myClassVector" should "return myClassVector" in {
            val test = Vector[Int](1, 3, 4)
            val cvec = new myClassVector(test)

            assertResult(cvec(3,9,12)){cvec * 3}
                                                                                           }

}

I would like to also note that:

assertResult((3,9,12)){cvec*3}

doesn't work either.

Thanks

nietsnegttiw
  • 371
  • 1
  • 5
  • 16

1 Answers1

2

If the class that you are testing (myClassVector) was declared as a case class then the compiler automatically created a equals method on your class that does a comparison of the fields in your class to test for equality. But if you declared myClassVector as a vanilla class (without the case keyword) then you will need to provide your own equals method.

Here is an example:

class myClassVector(val a: Int, val b: Int, val c: Int) {
  override def equals (that: Any) = that match {
    case that: myClassVector =>
      a == that.a && b == that.b && c == that.c
  }
}

Cheers!

Alfred Fazio
  • 956
  • 7
  • 10