What is the === (triple-equals) operator in Scala Koans?

浪子不回头ぞ 提交于 2019-12-18 11:38:22

问题


I started working my way through the Scala Koans, which is organized around a suite of unit tests with blanks that one needs to fill in. (This idea was modeled after a similar Ruby Koans project.) You start the sbt tool running a test, and it admonishes:

[info]   + ***************************************** 
[info]   +  
[info]   +  
[info]   +  
[info]   + Please meditate on koan "None equals None" of suite "AboutEmptyValues" 
[info]   +  
[info]   +  
[info]   +  
[info]   + ***************************************** 

...and so you go look at this unit test and it says:

test("None equals None") {
  assert(None === __)
}

...and, after meditation, you realize that you should fill in the blank like this:

test("None equals None") {
  assert(None === None)
}

...and then it moves on to the next unit test.

My question, though, is what is this === operator? I can't seem to find it anywhere. Is this a DSL operator defined in the Scala Koans project itself? Or is it part of the ScalaTest framework? Or in Scala proper?


回答1:


This is the triple-equals operator from ScalaTest. Have a look at this page: Getting Started with FunSuite. It says:

ScalaTest lets you use Scala's assertion syntax, but defines a triple equals operator (===) to give you better error messages. The following code would give you an error indicating only that an assertion failed:

assert(1 == 2)

Using triple equals instead would give you the more informative error message, "1 did not equal 2":

assert(1 === 2)


来源:https://stackoverflow.com/questions/10489548/what-is-the-triple-equals-operator-in-scala-koans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!