plusOrMinus strangeness

220 views
Skip to first unread message

ido

unread,
Mar 2, 2010, 9:33:00 AM3/2/10
to scalatest-users
@RunWith(classOf[JUnitRunner])
class PearsonSpecification extends FlatSpec with ShouldMatchers {

"test1" should "plusminus" in {
0.5 should equal (0.5 plusOrMinus 0.1)
}

"test2" should "plusminus" in {
0.5 should equal (0.5)
}
}


test2 passes but
for test1 I get:
org.scalatest.TestFailedException: 0.5 did not equal
DoubleTolerance(0.5,0.1)

Which I don't understand.
I use scalatest-1.0.1-for-scala-2.8.0.Beta1-SNAPSHOT

Bill Venners

unread,
Mar 2, 2010, 11:10:50 AM3/2/10
to scalate...@googlegroups.com
Hi,

You must use plusOrMinus with "be" not "equal". "equal" always
compares for equality by invoking == on one object, passing in the
other. "be" does different things depending on what object is being
passed. So try:

0.5 must be (0.5 plusOrMinus 0.1)

Bill

> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest
>

--
Bill Venners
Artima, Inc.
http://www.artima.com

Reply all
Reply to author
Forward
0 new messages