Skip to content

Instantly share code, notes, and snippets.

@ghassanpl
Created January 11, 2017 16:31
Show Gist options
  • Select an option

  • Save ghassanpl/793b6f2fbb46c787ae6f2a50882a213c to your computer and use it in GitHub Desktop.

Select an option

Save ghassanpl/793b6f2fbb46c787ae6f2a50882a213c to your computer and use it in GitHub Desktop.
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