Skip to content

Commit

Permalink
Merge branch 'dev' into dev-splitting-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
javierfernandes committed Dec 29, 2015
2 parents 21015bd + 0ea5392 commit 263c774
Show file tree
Hide file tree
Showing 13 changed files with 354 additions and 199 deletions.
Binary file not shown.
Binary file added org.uqbar.project.wollok.game/assets/speech.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion org.uqbar.project.wollok.game/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source.. = src/,\
xtend-gen/
xtend-gen/,\
assets/
bin.includes = META-INF/,\
.,\
lib/gdx-1.6.0.jar,\
Expand Down Expand Up @@ -33,4 +34,5 @@ jars.extra.classpath = lib/gdx-1.6.0.jar,\
lib/lwjgl-platform-2.9.2-natives-linux.jar,\
lib/lwjgl-platform-2.9.2-natives-osx.jar,\
lib/lwjgl-platform-2.9.2-natives-windows.jar
output.. = bin/

Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package org.uqbar.project.wollok.game.gameboard

import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration

class GameboardConfiguration extends LwjglApplicationConfiguration {
new (Gameboard gameboard) {
this.useGL30 = false;
this.resizable = false;

new(Gameboard gameboard) {
this.useGL30 = false
this.resizable = false
this.title = gameboard.title
this.width = gameboard.pixelWidth();
this.height = gameboard.pixelHeight();
this.addIcon("flying_bird.png", FileType.Internal);
this.width = gameboard.pixelWidth()
this.height = gameboard.pixelHeight()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.uqbar.project.wollok.game.AbstractPosition
import org.uqbar.project.wollok.game.Image

class Window {
val patch = new NinePatch(new Texture(Gdx.files.internal("assets/speech.png")), 30, 60, 40, 50)
val patch = new NinePatch(new Texture(Gdx.files.internal("speech.png")), 30, 60, 40, 50)
val textBitmap = new BitmapFont()
val batch = new SpriteBatch()
val font = new BitmapFont()
Expand Down
28 changes: 28 additions & 0 deletions org.uqbar.project.wollok.lib/src/wollok.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,32 @@ package lang {
return result
}

method subList(start,end) = {
if(this.isEmpty)
return this.newInstance()
val newList = this.newInstance()
start = start.limitBetween(0,this.size()-1)
end = end.limitBetween(0,this.size()-1)
(start..end).forEach([i| newList.add(this.get(i))])
return newList
}

method take(n) = {
if(n <= 0)
this.newInstance()
else
this.subList(0,n-1)
}

method drop(n) = {
if(n >= this.size())
this.newInstance()
else
this.subList(n,this.size()-1)
}

method reverse() = this.subList(this.size()-1,0)

// REFACTORME: DUP METHODS
method fold(initialValue, closure) native
method add(element) native
Expand All @@ -400,6 +425,9 @@ package lang {
method max(other) = if (this >= other) this else other
method min(other) = if (this <= other) this else other

method limitBetween(limitA,limitB) =if(limitA <= limitB) limitA.max(this).min(limitB)
else limitB.max(this).min(limitA)

method !=(other) = ! (this == other)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
package org.uqbar.project.wollok.tests.interpreter

import org.junit.Test
import org.uqbar.project.wollok.interpreter.core.WollokProgramExceptionWrapper

class CollectionTestCase extends AbstractWollokInterpreterTestCase {

def instantiateCollectionAsNumbersVariable() {
"val numbers = #[22, 2, 10]"
}

def instantiateStrings() {
"val strings = #['hello', 'hola', 'bonjour', 'ciao', 'hi']"
}

@Test
def void min() {
'''
program p {
«instantiateStrings»
assert.equals('hi', strings.min[e| e.length() ])
}'''.interpretPropagatingErrors
}

@Test
def void max() {
try
'''
program p {
«instantiateStrings»
val r = strings.max[e| e.length() ]
assert.equals('bonjour', strings.max[e| e.length() ])
}'''.interpretPropagatingErrors
catch (WollokProgramExceptionWrapper e)
fail(e.message)
}

@Test
def void size() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
assert.equals(3, numbers.size())
}'''.interpretPropagatingErrors
}

@Test
def void contains() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
assert.that(numbers.contains(22))
assert.that(numbers.contains(2))
assert.that(numbers.contains(10))
}'''.interpretPropagatingErrors
}

@Test
def void exists() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
assert.that(numbers.exists[e| e > 20])
assert.that(numbers.exists[e| e > 0])
assert.notThat(numbers.exists[e| e < 0])
}'''.interpretPropagatingErrors
}

@Test
def void remove() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
numbers.remove(22)
assert.that(2 == numbers.size())
}'''.interpretPropagatingErrors
}

@Test
def void clear() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
numbers.clear()
assert.that(0 == numbers.size())
}'''.interpretPropagatingErrors
}

@Test
def void isEmpty() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
assert.notThat(numbers.isEmpty())
}'''.interpretPropagatingErrors
}

@Test
def void forEach() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
var sum = 0
numbers.forEach([n | sum += n])
assert.equals(34, sum)
}'''.interpretPropagatingErrors
}

@Test
def void forAll() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
assert.that(numbers.forAll([n | n > 0]))
assert.notThat(numbers.forAll([n | n > 5]))
}'''.interpretPropagatingErrors
}

@Test
def void filter() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
var greaterThanFiveElements = numbers.filter([n | n > 5])
assert.that(greaterThanFiveElements.size() == 2)
}'''.interpretPropagatingErrors
}

@Test
def void map() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
var halfs = numbers.map([n | n / 2])
assert.equals(3, halfs.size())
assert.that(halfs.contains(11))
assert.that(halfs.contains(5))
assert.that(halfs.contains(1))
}'''.interpretPropagatingErrors
}

@Test
def void shortCutAvoidingParenthesis() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
var greaterThanFiveElements = numbers.filter[n | n > 5]
assert.that(greaterThanFiveElements.size() == 2)
}'''.interpretPropagatingErrors
}

@Test
def void any() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
val any = numbers.any()
assert.that(numbers.contains(any))
}'''.interpretPropagatingErrors
}

@Test
def void equalsWithMethodName() {
'''
program p {
val a = #[23, 2, 1]
val b = #[23, 2, 1]
assert.that(a.equals(b))
}'''.interpretPropagatingErrors
}

@Test
def void equalsWithEqualsEquals() {
'''
program p {
val a = #[23, 2, 1]
val b = #[23, 2, 1]
assert.that(a == b)
}'''.interpretPropagatingErrors
}

@Test
def void testToString() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
assert.equals("#[22, 2, 10]", numbers.toString())
}'''.interpretPropagatingErrors
}

@Test
def void testToStringWithObjectRedefiningToStringInWollok() {
'''
object myObject {
method internalToSmartString(alreadyShown) = "My Object"
}
program p {
val a = #[23, 2, 1, myObject]
assert.equals("#[23, 2, 1, My Object]", a.toString())
}'''.interpretPropagatingErrors
}

@Test
def void detect() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
assert.equals(22, numbers.detect[e| e > 20])
assert.equals(null, numbers.detect[e| e > 1000])
}
'''.interpretPropagatingErrors
}

@Test
def void count() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
assert.equals(1, numbers.count[e| e > 20])
assert.equals(3, numbers.count[e| e > 0])
assert.equals(0, numbers.count[e| e < 0])
}
'''.interpretPropagatingErrors
}

@Test
def void sum() {
'''
program p {
«instantiateCollectionAsNumbersVariable»
assert.equals(34, numbers.sum([n | n]))
}'''.interpretPropagatingErrors
}

}
Loading

0 comments on commit 263c774

Please sign in to comment.