Skip to content

Commit

Permalink
added #toEqualAsArrays method in Koan.st to properly test arrays agai…
Browse files Browse the repository at this point in the history
…nst OrderedCollection and SortedCollection
  • Loading branch information
Dmitrii Samoilov committed Apr 3, 2012
1 parent b048330 commit eabb2ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/koans/TestOrderedCollection.st
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Koan subclass: TestOrderedCollection [


orderedCollection := OrderedCollection with: $a with: $b with: $c with: $d with: $e. orderedCollection := OrderedCollection with: $a with: $b with: $c with: $d with: $e.


self expect: fillMeIn toEqual: (orderedCollection asArray). self expect: fillMeIn toEqualAsArrays: orderedCollection.
self expect: [ OrderedCollection with: 'a' with: 'b' with: 'c' with: 'd' with: 'e' with: 'f' ] toRaise: fillMeIn. self expect: [ OrderedCollection with: 'a' with: 'b' with: 'c' with: 'd' with: 'e' with: 'f' ] toRaise: fillMeIn.


"OrderedCollection responds to most messages that Array responds to." "OrderedCollection responds to most messages that Array responds to."
Expand All @@ -31,7 +31,7 @@ Koan subclass: TestOrderedCollection [


orderedCollection := OrderedCollection new addAll: #(5 6 7); yourself. orderedCollection := OrderedCollection new addAll: #(5 6 7); yourself.


self expect: fillMeIn toEqual: orderedCollection. self expect: fillMeIn toEqualAsArrays: orderedCollection.
] ]


testAddElements [ testAddElements [
Expand All @@ -40,19 +40,19 @@ Koan subclass: TestOrderedCollection [
orderedCollection := OrderedCollection with: 1. orderedCollection := OrderedCollection with: 1.
orderedCollection addFirst: 2. orderedCollection addFirst: 2.


self expect: fillMeIn toEqual: orderedCollection. self expect: fillMeIn toEqualAsArrays: orderedCollection.


orderedCollection addLast: 3. orderedCollection addLast: 3.


self expect: fillMeIn toEqual: orderedCollection. self expect: fillMeIn toEqualAsArrays: orderedCollection.


orderedCollection add: 4 afterIndex: 2. orderedCollection add: 4 afterIndex: 2.


self expect: fillMeIn toEqual: orderedCollection. self expect: fillMeIn toEqualAsArrays: orderedCollection.


orderedCollection add: 5 beforeIndex: 2. orderedCollection add: 5 beforeIndex: 2.


self expect: fillMeIn toEqual: orderedCollection. self expect: fillMeIn toEqualAsArrays: orderedCollection.
] ]


testRemoveElements [ testRemoveElements [
Expand All @@ -61,15 +61,15 @@ Koan subclass: TestOrderedCollection [
orderedCollection := OrderedCollection with: 1 with: 2 with: 3 with: 4. orderedCollection := OrderedCollection with: 1 with: 2 with: 3 with: 4.
orderedCollection removeFirst. orderedCollection removeFirst.


self expect: fillMeIn toEqual: orderedCollection. self expect: fillMeIn toEqualAsArrays: orderedCollection.


orderedCollection removeLast. orderedCollection removeLast.


self expect: fillMeIn toEqual: orderedCollection. self expect: fillMeIn toEqualAsArrays: orderedCollection.


orderedCollection removeAtIndex: 1. orderedCollection removeAtIndex: 1.


self expect: fillMeIn toEqual: orderedCollection. self expect: fillMeIn toEqualAsArrays: orderedCollection.
] ]


testAccessingElements [ testAccessingElements [
Expand Down
2 changes: 1 addition & 1 deletion src/koans/TestSortedCollection.st
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Koan subclass: TestSortedCollection [
add: 3; add: 3;
add: 4. add: 4.


self expect: fillMeIn toEqual: sortedCollection. self expect: fillMeIn toEqualAsArrays: sortedCollection.
] ]


testComparingSortedCollections [ testComparingSortedCollections [
Expand Down
6 changes: 6 additions & 0 deletions src/lib/Koan.st
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Object subclass: Koan [
ifFalse: [ self setTrackerToFalse: 'Expected value SHOULD equal actual value.' expected: expectedValue actual: actualValue ]. ifFalse: [ self setTrackerToFalse: 'Expected value SHOULD equal actual value.' expected: expectedValue actual: actualValue ].
] ]


expect: expectedValue toEqualAsArrays: actualValue [
tracker status ifFalse: [^nil].
(expectedValue asArray = actualValue asArray)
ifFalse: [ self setTrackerToFalse: 'Expected array/collection SHOULD equal actual array/collection.' expected: expectedValue actual: actualValue ].
]

expect: expectedValue toNotEqual: actualValue [ expect: expectedValue toNotEqual: actualValue [
tracker status ifFalse: [^nil]. tracker status ifFalse: [^nil].
(expectedValue = actualValue) (expectedValue = actualValue)
Expand Down

0 comments on commit eabb2ad

Please sign in to comment.