Created
January 11, 2017 16:31
-
-
Save ghassanpl/793b6f2fbb46c787ae6f2a50882a213c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| Tinytalk include: "stdlib/Tests.tt" | |
| /* | |
| OrderedCollection | |
| The default implementation works with integer keys. | |
| */ | |
| OrderedCollection add-method: { first | |
| "Returns the first element of the collection." | |
| ^ self at: 0 | |
| } | |
| OrderedCollection add-method: { last | |
| "Returns the last element of the collection." | |
| ^ self at: self size - 1 | |
| } | |
| Tests for: OrderedCollection add: [ :test | | |
| "Test `first` and `last` for String and Array" | |
| | oc | | |
| oc = "low" | |
| test assert-equal: [ oc first ] to: [ #l to-char ] | |
| test assert-equal: [ oc last ] to: [ #w to-char ] | |
| oc = #( 1 2 3 ) | |
| test assert-equal: [ oc first ] to: [ 1 ] | |
| test assert-equal: [ oc last ] to: [ 3 ] | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment