Skip to content

Commit

Permalink
List.get using rounding half up (#2002)
Browse files Browse the repository at this point in the history
* List.get using rounding half up

* Upgrading to last changes in wollok-language
  • Loading branch information
fdodino authored Jul 9, 2021
1 parent f05baab commit 8da93d3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 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
2 changes: 2 additions & 0 deletions org.uqbar.project.wollok/src/wollok/lang/Exception.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Exception {
.reverse
}

def initialize() {}

def getStackTrace() {
stackTrace.map[
exceptionObject.call("createStackTraceElement", contextDescription.javaToWollok, location.toString.javaToWollok)
Expand Down
2 changes: 1 addition & 1 deletion wollok-language

0 comments on commit 8da93d3

Please sign in to comment.