Export to GitHub

specs - issue #71

Spec assert failures should include type information?


Posted on Apr 30, 2009 by Grumpy Dog

I had an issue where when I ran my tests, an assertion failed with the following message: '0.0010' is not equal to '0.0010'

The problem was comparing a float to a double.

Shouldn't the output mention the type information? Shouldn't the compiler have barfed? I'm new to Scala so I don't really know how the comparison between different numeric types works completely. Correct me if I am wrong. I found this a tad annoying and non-obvious.

I'm coming from a Haskell background where the compiler disallows me from comparing a Float and a Double.

Thanks

Comment #1

Posted on Apr 30, 2009 by Grumpy Dog

This is using specs version 1.4.4.

Comment #2

Posted on May 1, 2009 by Massive Giraffe

That's a very good idea.

I've added the type information when the toString values are the same:

"provide the type of the objects in the failure message when their toString method return the same value" in { val d: Double = 0.1 val f: Float = 0.1f expectation(f must_== d) must failWith("'0.1': Float is not equal to '0.1': Double") }

This is available here: http://scala-tools.org/repo-snapshots/org/scala- tools/testing/specs/1.5.0-SNAPSHOT/

Comment #3

Posted on Feb 14, 2010 by Massive Giraffe

(No comment was entered for this change.)

Status: Verified

Labels:
Type-Defect Priority-Medium