forked from sl4m/gnu_smalltalk_koans
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added TestDictionary, TestIteration, TestBoolean, TestException, Test…
…Class, refactored existing koans
- Loading branch information
skim
committed
Jun 20, 2011
1 parent
0e0e8fa
commit 62203f9
Showing
19 changed files
with
418 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,72 @@ | ||
Koan subclass: TestBoolean [ | ||
<comment: 'A collection of boolean tests.'> | ||
|
||
testIfTrueAndIfFalse [ | ||
| result anotherResult | | ||
|
||
(1 < 2) | ||
ifTrue: [ result := true ] | ||
ifFalse: [ result := false ]. | ||
((5 + 2 * 9) < 25 ) | ||
ifTrue: [ anotherResult := true ] | ||
ifFalse: [ anotherResult := false ]. | ||
|
||
self expect: (self fillMeIn) toEqual: (result). | ||
self expect: (self fillMeIn) toEqual: (anotherResult). | ||
truthValue: condition [ | ||
condition ifTrue: [ ^#trueStuff ]. | ||
condition ifFalse: [ ^#falseStuff ]. | ||
] | ||
|
||
testTrueIsTreatedAsTrue [ | ||
self expect: (self fillMeIn) toEqual: (self truthValue: true). | ||
] | ||
|
||
testFalseIsTreatedAsFalse [ | ||
self expect: (self fillMeIn) toEqual: (self truthValue: false). | ||
] | ||
|
||
testNilIsNotTreatedAsABoolean [ | ||
self expect: [ self truthValue: nil ] toRaise: (self fillMeIn). | ||
] | ||
|
||
testIfTrueAndIfFalseOnlyRespondsToBooleans [ | ||
self expect: [ self truthValue: 1 ] toRaise: (self fillMeIn). | ||
self expect: [ self truthValue: 0 ] toRaise: (self fillMeIn). | ||
self expect: [ self truthValue: #() ] toRaise: (self fillMeIn). | ||
self expect: [ self truthValue: 'String' ] toRaise: (self fillMeIn). | ||
self expect: [ self truthValue: '' ] toRaise: (self fillMeIn). | ||
] | ||
|
||
testAndShortCircuit [ | ||
| x y z | | ||
|
||
x := 4. y := 10. z := 0. | ||
|
||
self expect: (self fillMeIn) toEqual: (x < 5 and: [ z := 1. y < 11 ]). | ||
self expect: (self fillMeIn) toEqual: z. | ||
|
||
z := 0. | ||
|
||
self expect: (self fillMeIn) toEqual: (x < 4 and: [ z := 1. y < 11 ]). | ||
self expect: (self fillMeIn) toEqual: z. | ||
|
||
"How is this different from '&'?" | ||
] | ||
|
||
testOrShortCircuit [ | ||
| x y z | | ||
|
||
x := 4. y := 10. z := 0. | ||
|
||
self expect: (self fillMeIn) toEqual: (x > 5 or: [ z := 1. y > 9]). | ||
self expect: (self fillMeIn) toEqual: z. | ||
|
||
z := 0. | ||
|
||
self expect: (self fillMeIn) toEqual: (x > 9 sqrt or: [ z := 1. y > 9]). | ||
self expect: (self fillMeIn) toEqual: z. | ||
] | ||
|
||
testEqv [ | ||
self expect: (self fillMeIn) toEqual: (true eqv: true). | ||
self expect: (self fillMeIn) toEqual: (true eqv: false). | ||
self expect: (self fillMeIn) toEqual: (false eqv: true). | ||
self expect: (self fillMeIn) toEqual: (false eqv: false). | ||
] | ||
|
||
testXor [ | ||
self expect: (self fillMeIn) toEqual: (true xor: true). | ||
self expect: (self fillMeIn) toEqual: (true xor: false). | ||
self expect: (self fillMeIn) toEqual: (false xor: true). | ||
self expect: (self fillMeIn) toEqual: (false xor: false). | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,90 @@ | ||
Koan subclass: TestClass [ | ||
<comment: 'A collection of class tests.'> | ||
Object subclass: HelloWorld [ | ||
<comment: 'This is a HelloWorld comment'> | ||
<category: 'This is a HelloWorld category'> | ||
|
||
Statement := $S. | ||
|
||
| instanceVariable | | ||
|
||
"Unlike other Smalltalks, method statements are inside brackets." | ||
|
||
"Class variables are defined the same as variable assignments." | ||
awesome [ | ||
^true | ||
] | ||
|
||
+ string [ | ||
^'Hello ', string | ||
] | ||
|
||
"Pragmas define class comment, class category, imported namespaces, and the shape of indexed instance variables." | ||
say: something [ | ||
^self class name asString, ' says ', something | ||
] | ||
] | ||
|
||
HelloWorld subclass: SubHelloWorld [] | ||
|
||
Koan subclass: TestClass [ | ||
<comment: 'A collection of class tests.'> | ||
|
||
"Class variables are defined the same as variable assignments." | ||
|
||
"superclass" | ||
"allInstances" | ||
"allSuperclasses" | ||
|
||
testName [ | ||
self expect: (self fillMeIn) toEqual: HelloWorld name. | ||
] | ||
|
||
testPragmas [ | ||
" | ||
Pragmas define: | ||
class comment | ||
class category | ||
imported namespaces | ||
shape of indexed instance variables. | ||
" | ||
|
||
self expect: (self fillMeIn) toEqual: HelloWorld comment. | ||
self expect: (self fillMeIn) toEqual: HelloWorld category. | ||
] | ||
|
||
testInstanceVariableCollection [ | ||
self expect: (self fillMeIn) toEqual: HelloWorld instVarNames. | ||
] | ||
|
||
testClassInstanceVariableCollection [ | ||
self expect: (self fillMeIn) toEqual: HelloWorld classVarNames asArray. | ||
] | ||
|
||
testMessageCollection [ | ||
self expect: (self fillMeIn) toEqual: HelloWorld selectors asArray. | ||
] | ||
|
||
testSourceCodeAt [ | ||
" | ||
#sourceCodeAt: returns the source code of the specified message. | ||
For example: HelloWorld sourceCodeAt: #+ would return: | ||
'+ string [ | ||
^''Hello '', string | ||
]' | ||
" | ||
] | ||
|
||
testAllInstances [ | ||
| helloWorld | | ||
|
||
helloWorld := HelloWorld new. | ||
|
||
self expect: (self fillMeIn) toEqual: (HelloWorld allInstances asArray). | ||
] | ||
|
||
testSuperclass [ | ||
self expect: (self fillMeIn) toEqual: (HelloWorld superclass). | ||
] | ||
|
||
testAllSubclasses [ | ||
self expect: (self fillMeIn) toEqual: (HelloWorld allSubclasses asArray). | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.