I've written a median function and want to add some unit tests for it.
So I wrote this in specs2
class TestStats extends Specification {
"Median function " should {
"be None for an empty list" in { Stats.median([]) must beNone }
"be the midpoint of an odd length list" in { Stats.median([1,2,3]) must_== Some(2)}
"be the average of the two midpoints of an even length list" in { Stats.median([1,2,3,4]) must_== Some(2.5)}
}
}
However, it doesn't compile with the error No implicit view available from Option[Double] => org.specs2.execute.Result.
on the "be None...
line.
I don't understand why it's asking for this in here. Am I really supposed to write an implicit myself to do this comparison?
Edit So the issue was purely syntactical - see my answer below. I'm a little annoyed that a syntax error was reported to me as a semantic error, which is why it never occurred to me that my list literals were wrong.
[]
,[1,2,3]
and[1,2,3,4]
are invalid Scala code. – Daniel C. SobralStats.median
? – Daniel C. Sobral