Permalink
Browse files

src: Answer koans

  • Loading branch information...
Greg Guthe
Greg Guthe committed Oct 1, 2012
1 parent 9f6e3d0 commit 0ce9097d70bb1b5026c6e87be6e6f87b20d3b49e
View
@@ -6,9 +6,9 @@ Koan subclass: TestArray [
emptyArray := Array new.
- self expect: fillMeIn toEqual: emptyArray class.
- self expect: fillMeIn toEqual: emptyArray size.
- self expect: fillMeIn toEqual: emptyArray isEmpty.
+ self expect: Array toEqual: emptyArray class.
+ self expect: 0 toEqual: emptyArray size.
+ self expect: true toEqual: emptyArray isEmpty.
"Not sure why you would do this. See the next koan."
]
@@ -20,12 +20,12 @@ Koan subclass: TestArray [
array := Array new: 4.
- self expect: fillMeIn toEqual: array size.
- self expect: fillMeIn toEqual: array isEmpty.
+ self expect: 4 toEqual: array size.
+ self expect: false toEqual: array isEmpty.
"Array index starts at 1, not 0 like most languages."
- self expect: fillMeIn toEqual: (array at: 1).
+ self expect: nil toEqual: (array at: 1).
"Arrays can accept any kind of object."
@@ -35,27 +35,27 @@ Koan subclass: TestArray [
at: 3 put: false;
at: 4 put: $x.
- self expect: fillMeIn toEqual: (array at: 1).
- self expect: fillMeIn toEqual: (array at: 2).
- self expect: fillMeIn toEqual: (array at: 3).
- self expect: fillMeIn toEqual: (array at: 4).
+ self expect: 'abc' toEqual: (array at: 1).
+ self expect: 10 toEqual: (array at: 2).
+ self expect: false toEqual: (array at: 3).
+ self expect: $x toEqual: (array at: 4).
]
testCreatingAnArrayWithUpToFiveInitialValues [
| array |
array := Array with: 2 with: 4 with: 6 with: 8 with: 10.
- self expect: fillMeIn toEqual: array.
- self expect: [ Array with: 1 with: 3 with: 5 with: 7 with: 9 with: 11 ] toRaise: fillMeIn.
+ self expect: array toEqual: array.
+ self expect: [ Array with: 1 with: 3 with: 5 with: 7 with: 9 with: 11 ] toRaise: MessageNotUnderstood.
]
testConstantArraysAreImmutable [
| array |
array := #('a' 'b' 'c').
- self expect: [ array at: 1 put: 'd' ] toRaise: fillMeIn.
+ self expect: [ array at: 1 put: 'd' ] toRaise: SystemExceptions.ReadOnlyObject.
"#() only accepts literal values."
]
@@ -66,47 +66,47 @@ Koan subclass: TestArray [
array := (Array new: 4) at: 1 put: 1; yourself.
array at: 1 put: 2.
- self expect: fillMeIn toEqual: (array at: 1).
+ self expect: 2 toEqual: (array at: 1).
]
testCreatingAnArrayThatEvaluatesExpressions [
| array |
array := { 1-1 . 2 squared . 3+4 }.
- self expect: fillMeIn toEqual: array.
+ self expect: #(0 4 7) toEqual: array.
array at: 1 put: 5.
- self expect: fillMeIn toEqual: array.
+ self expect: #(5 4 7) toEqual: array.
]
testAccessingElements [
| array |
array := #(0 1 2 3).
- self expect: fillMeIn toEqual: (array at: 1).
- self expect: fillMeIn toEqual: array first.
- self expect: fillMeIn toEqual: array second.
- self expect: fillMeIn toEqual: array third.
- self expect: fillMeIn toEqual: array fourth.
+ self expect: 0 toEqual: (array at: 1).
+ self expect: 0 toEqual: array first.
+ self expect: 1 toEqual: array second.
+ self expect: 2 toEqual: array third.
+ self expect: 3 toEqual: array fourth.
]
testIncludesElement [
| array |
array := Array with: 1 with: 2 with: 3.
- self expect: fillMeIn toEqual: (array includes: 2).
- self expect: fillMeIn toEqual: (array includes: 4).
+ self expect: true toEqual: (array includes: 2).
+ self expect: false toEqual: (array includes: 4).
]
testOccurrences [
| array |
array := #(1 2 2 3 4 4 2 6 8).
- self expect: fillMeIn toEqual: (array occurrencesOf: 2).
+ self expect: 3 toEqual: (array occurrencesOf: 2).
]
]
View
@@ -4,15 +4,15 @@ Koan subclass: TestAssert [
"Look at me, I'm a comment! All comments are wrapped in double quotes."
testTruth [
- self expectToBeTrue: false. "make this true"
+ self expectToBeTrue: true. "make this true"
"Note: all statements end with a period."
]
testEquality [
| expectedValue | "This is declaring a variable 'expectedValue'"
- expectedValue := fillMeIn. "':=' is an assignment operator"
+ expectedValue := 10. "':=' is an assignment operator"
"Hint: replace 'fillMeIn' with the expected value."
self expect: expectedValue toEqual: (5 + 5).
@@ -23,15 +23,15 @@ Koan subclass: TestAssert [
testStringEquality [
| expectedValue |
- expectedValue := fillMeIn.
+ expectedValue := 'hello world!'.
self expect: expectedValue toEqual: 'hello world!'.
]
testNotEqual [
| value |
- value := 'some value'. "make this a different value"
+ value := 'not some value'. "make this a different value"
self expect: value toNotEqual: 'some value'.
]
@@ -6,61 +6,61 @@ Koan subclass: TestAssociation [
association := #a -> 0.
- self expect: fillMeIn toEqual: association key.
- self expect: fillMeIn toEqual: association value.
+ self expect: #a toEqual: association key.
+ self expect: 0 toEqual: association value.
anotherAssociation := Association new key: #b value: 1.
- self expect: fillMeIn toEqual: anotherAssociation key.
- self expect: fillMeIn toEqual: anotherAssociation value.
+ self expect: #b toEqual: anotherAssociation key.
+ self expect: 1 toEqual: anotherAssociation value.
andAnotherAssociation := Association key: #c value: 2.
- self expect: fillMeIn toEqual: andAnotherAssociation key.
- self expect: fillMeIn toEqual: andAnotherAssociation value.
+ self expect: #c toEqual: andAnotherAssociation key.
+ self expect: 2 toEqual: andAnotherAssociation value.
]
testAssociationKeysCanBeAnyObject [
| association obj |
association := 'a' -> 0.
- self expect: fillMeIn toEqual: association key.
+ self expect: 'a' toEqual: association key.
association := 0 -> 1.
- self expect: fillMeIn toEqual: association key.
+ self expect: 0 toEqual: association key.
association := true -> 2.
- self expect: fillMeIn toEqual: association key.
+ self expect: true toEqual: association key.
association := nil -> 3.
- self expect: fillMeIn toEqual: association key.
+ self expect: nil toEqual: association key.
association := $b -> 4.
- self expect: fillMeIn toEqual: association key.
+ self expect: $b toEqual: association key.
obj := Object new.
association := obj -> 5.
- self expect: fillMeIn toEqual: association key.
+ self expect: obj toEqual: association key.
]
testComparingAssociations [
| association anotherAssociation |
association := Association key: #a value: 0.
- self expect: fillMeIn toEqual: (association = (#a -> 0)).
+ self expect: true toEqual: (association = (#a -> 0)).
anotherAssociation := Association key: #b value: 1.
- self expect: fillMeIn toEqual: (association = (#b -> 2)).
- self expect: fillMeIn toEqual: (association = (#c -> 1)).
+ self expect: false toEqual: (association = (#b -> 2)).
+ self expect: false toEqual: (association = (#c -> 1)).
]
testAssociationsActLikeSingletons [
@@ -69,6 +69,6 @@ Koan subclass: TestAssociation [
association := Association new key: #a value: 0.
anotherAssociation := #a -> 0.
- self expect: fillMeIn toEqual: (association = anotherAssociation).
+ self expect: true toEqual: (association = anotherAssociation).
]
]
View
@@ -9,9 +9,9 @@ Koan subclass: TestBag [
bag add: 'b' withOccurrences: 1.
bag add: 'c'.
- self expect: fillMeIn toEqual: (bag occurrencesOf: 'a').
- self expect: fillMeIn toEqual: (bag occurrencesOf: 'b').
- self expect: fillMeIn toEqual: (bag occurrencesOf: 'c').
+ self expect: 2 toEqual: (bag occurrencesOf: 'a').
+ self expect: 1 toEqual: (bag occurrencesOf: 'b').
+ self expect: 1 toEqual: (bag occurrencesOf: 'c').
]
testCollectionIsNotIndexable [
@@ -21,7 +21,7 @@ Koan subclass: TestBag [
bag add: 1 withOccurrences: 3.
bag add: 2.
- self expect: [ bag at: 1 ] toRaise: fillMeIn.
+ self expect: [ bag at: 1 ] toRaise: SystemExceptions.NotIndexable.
]
testComparingBags [
@@ -35,6 +35,6 @@ Koan subclass: TestBag [
anotherBag add: 2 withOccurrences: 3.
anotherBag add: 1 withOccurrences: 4.
- self expect: fillMeIn toEqual: (bag = anotherBag).
+ self expect: true toEqual: (bag = anotherBag).
]
]
View
@@ -10,8 +10,8 @@ Koan subclass: TestBasic [
anotherDeclaration := 'string'. "typical way to assign value
(this will be used throughout the koans)"
- self expect: fillMeIn toEqual: declaration.
- self expect: fillMeIn toEqual: anotherDeclaration.
+ self expect: 1 toEqual: declaration.
+ self expect: 'string' toEqual: anotherDeclaration.
]
testEqualSignIsNotAnAssignmentOperator [
@@ -20,7 +20,7 @@ Koan subclass: TestBasic [
variableA := variableB := 1234. "multiple assignments work"
value := variableA = variableB. "equal is not used for assignment"
- self expect: fillMeIn toEqual: (variableA = variableB).
+ self expect: true toEqual: (variableA = variableB).
"#== is a message that checks if identity is equal. More about messages in the TestMessage koan."
]
@@ -31,13 +31,13 @@ Koan subclass: TestBasic [
"Multiple statements are separated by periods."
variableA := 1. variableB := 2. variableC := 3.
- self expect: fillMeIn toEqual: variableA.
- self expect: fillMeIn toEqual: variableB.
- self expect: fillMeIn toEqual: variableC.
+ self expect: 1 toEqual: variableA.
+ self expect: 2 toEqual: variableB.
+ self expect: 3 toEqual: variableC.
]
testInequality [
- self expect: fillMeIn toEqual: ('hello' ~= 'world').
+ self expect: true toEqual: ('hello' ~= 'world').
"#~~ is a message that checks if identity is not equal. More about messages in the TestMessage koan."
]
@@ -47,18 +47,18 @@ Koan subclass: TestBasic [
expression := (3 > 4) | (5 < 6).
- self expect: fillMeIn toEqual: expression.
+ self expect: true toEqual: expression.
]
testLogicalAnd [
| expression |
expression := (2 > 1) & ('a' < 'b').
- self expect: fillMeIn toEqual: expression.
+ self expect: true toEqual: expression.
]
testNot [
- self expect: fillMeIn toEqual: true not.
+ self expect: false toEqual: true not.
]
]
Oops, something went wrong.

0 comments on commit 0ce9097

Please sign in to comment.