Skip to content

Commit

Permalink
Merge pull request #30 from lucretiomsp/map-funtion
Browse files Browse the repository at this point in the history
Map function
  • Loading branch information
lucretiomsp authored May 13, 2024
2 parents 69b1f83 + e7b3763 commit 5172590
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Coypu/Interval.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Extension { #name : #Interval }

{ #category : #'*Coypu' }
Interval >> map: value to: range [

^ value - self first / (self last - self first)
* (range last - range first) + range first
]
11 changes: 11 additions & 0 deletions src/Coypu/IntervalTest.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Extension { #name : #IntervalTest }

{ #category : #'*Coypu' }
IntervalTest >> testMapTo [

self assert: ((0 to: 10) map: 1 to: (10 to: 20)) equals: 11.
self assert: ((0 to: 10) map: 5 to: (0 to: 100)) equals: 50.

self assert: ((0 to: 10) map: 20 to: (0 to: 100)) equals: 200.
self assert: ((0 to: 10) map: -1 to: (0 to: 100)) equals: -10
]

0 comments on commit 5172590

Please sign in to comment.