Scala Koans 中的 === (triple-equals) 运算符是什么? [英] What is the === (triple-equals) operator in Scala Koans?
问题描述
我开始研究 Scala Koans,它围绕一套单元测试组织,其中包含需要填补的空白(这个想法模仿了一个类似的 Ruby Koans 项目.)你启动 sbt 工具运行一个测试,它警告:
<前>[信息] + *********************************************[信息] +[信息] +[信息] +[信息] + 请沉思AboutEmptyValues"套件的公案无等于无"[信息] +[信息] +[信息] +[信息] + *********************************************...所以你去看看这个单元测试,它说:
<前>测试(无等于无"){断言(无 === __)}...而且,在冥想之后,你意识到你应该像这样填空:
<前>测试(无等于无"){断言(无 === 无)}...然后它继续进行下一个单元测试.
不过,我的问题是这个 ===
运算符是什么?我似乎无法在任何地方找到它.这是 Scala Koans 项目本身定义的 DSL 运算符吗?或者它是 ScalaTest 框架的一部分?还是在 Scala 中?
这是来自 ScalaTest一>.看看这个页面:FunSuite 入门.它说:
<块引用>ScalaTest 允许您使用 Scala 的断言语法,但定义了一个三元组等于运算符 (===) 为您提供更好的错误消息.以下代码会给你一个错误,表明断言失败:
assert(1 == 2)
改用三重等于会给你提供更多信息的错误消息,1 不等于 2":
assert(1 === 2)
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?
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)
这篇关于Scala Koans 中的 === (triple-equals) 运算符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!