Skip to content

Commit

Permalink
List.get using rounding half up
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Jul 1, 2021
1 parent 68caf41 commit 83c2dbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions org.uqbar.project.wollok.lib/src/wollok/lang/WList.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.uqbar.project.wollok.interpreter.nativeobj.JavaWrapper
import static extension org.uqbar.project.wollok.interpreter.nativeobj.WollokJavaConversions.*
import static extension org.uqbar.project.wollok.lib.WollokSDKExtensions.*
import static extension org.uqbar.project.wollok.utils.WollokObjectUtils.*
import java.math.RoundingMode

/**
* Native part of the wollok.lang.List class
Expand All @@ -27,8 +28,9 @@ class WList extends WCollection<List<WollokObject>> implements JavaWrapper<List<

def get(BigDecimal index) {
index.checkNotNull("get")
val convertedIndex = index.coerceToPositiveInteger
wrapped.get(convertedIndex)
index.coerceToPositiveInteger
val convertedIndex = index.setScale(0, RoundingMode.HALF_UP)
wrapped.get(convertedIndex.intValue)
}

def sortBy(WollokObject predicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class NumbersConfigurationTruncateStrategyTestCase extends AbstractWollokInterpr
@Test
def void listGet() {
'''
assert.equals("hola", ["saludo", "hola", "jua"].get(1.99999))
assert.equals("jua", ["saludo", "hola", "jua"].get(1.99999))
'''.test
}

Expand Down

0 comments on commit 83c2dbb

Please sign in to comment.