rll*_*rll 2 smalltalk squeak pharo pharo-5
我开始学习使用Pharo 5的Smalltalk.我现在正在接受来自吱吱声的人的教程,以便对语法等有一定的掌握.
我在开始时,我只有两个类(一个类BlankCell和一个BlanCellTestCase类用于单元测试).Blankcell已经实现了一些消息,我在第1.9节的最后.
行为很好,因为在操场上:
| cell exit |
cell := BlankCell new.
exit := cell exitSideFor: #north.
exit = #south
"the last statement properly returns a true or false"
Run Code Online (Sandbox Code Playgroud)
在测试用例上有三个测试,只有一个失败(与exitSide相关):
testCellExitSides
"Test the exit sides."
| cell exit |
cell := BlankCell new.
exit := cell exitSideFor: #north.
self assert: [ exit = #south ].
exit := cell exitSideFor: #east.
self assert: [ exit = #west ].
exit := cell exitSideFor: #south.
self assert: [ exit = #north ].
exit := cell exitSideFor: #west.
self assert: [ exit = #east ].
Run Code Online (Sandbox Code Playgroud)
错误消息是
MessageNotUnderstood:BlockClosure>>ifFalse:
Run Code Online (Sandbox Code Playgroud)
该doesNotUnderstand消息被发送指向句子的参数[ exit = #south ]
有谁知道这里可能会发生什么?
TestCase>>assert: 期望一个布尔值,而不是一个块.
所以
self assert: [ exit = #south ].
应该写成
self assert: exit = #south
对于字符串比较,最好的方法是使用以下内容:
self assert: exit equals: #south
因为这样你会看到字符串的差异,只是一个布尔故障.
但
Object>>assert: 期望一个块,而不是布尔值.
但是,您可以在常规代码中使用此断言,而不是代码测试.