diff --git a/.gitignore b/.gitignore index 02970349..0a8e1fb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin -.history \ No newline at end of file +.history +log diff --git a/test/sanity/basics/booleans/literals.wtest b/test/sanity/basics/booleans/literals.wtest index bfb572c9..349eb841 100644 --- a/test/sanity/basics/booleans/literals.wtest +++ b/test/sanity/basics/booleans/literals.wtest @@ -75,4 +75,9 @@ describe "booleans - tests with literals" { assert.notThat({false}.apply() || {false}.apply()) } + test "toString" { + assert.equals("true", true.toString()) + assert.equals("false", false.toString()) + } + } diff --git a/test/sanity/basics/numbers/operators.wtest b/test/sanity/basics/numbers/operators.wtest index 39dcdbed..31c168cc 100644 --- a/test/sanity/basics/numbers/operators.wtest +++ b/test/sanity/basics/numbers/operators.wtest @@ -272,4 +272,9 @@ describe "Number operators" { assert.equals(1, +1) } + test "coerceToInteger" { + assert.equals(2, 2.coerceToInteger()) + assert.equals(-1, -1.coerceToInteger()) + } + } \ No newline at end of file diff --git a/test/sanity/basics/numbers/roundingDecimals.wtest b/test/sanity/basics/numbers/roundingDecimals.wtest index dbc9e9b7..54d34d58 100644 --- a/test/sanity/basics/numbers/roundingDecimals.wtest +++ b/test/sanity/basics/numbers/roundingDecimals.wtest @@ -88,4 +88,9 @@ describe "Decimal tests"{ assert.equals(-1, (-1.5).round()) } + test "coerceToInteger" { + assert.equals(2, 2.2.coerceToInteger()) + assert.equals(2, 2.7.coerceToInteger()) + } + } diff --git a/test/sanity/basics/ranges/ranges.wtest b/test/sanity/basics/ranges/ranges.wtest index ee32d5c3..88848f07 100644 --- a/test/sanity/basics/ranges/ranges.wtest +++ b/test/sanity/basics/ranges/ranges.wtest @@ -100,6 +100,12 @@ describe "ranges" { assert.that(range.contains(anyOne)) } + test "anyOne inverse range" { + const range = new Range(start= 10, end = -5,step = -7) + const anyOne = range.anyOne() + assert.that(range.contains(anyOne)) + } + test "anyOne probability" { const range = 0 .. 10 range.step(2) diff --git a/test/sanity/basics/strings/strings.wtest b/test/sanity/basics/strings/strings.wtest index 76f88590..b38f0469 100644 --- a/test/sanity/basics/strings/strings.wtest +++ b/test/sanity/basics/strings/strings.wtest @@ -28,7 +28,7 @@ describe "strings" { assert.throwsException( { "hola".substring(null) }) } - test "substring in first parameter fail" { + test "substring in first parameter should fail" { assert.throwsException({ "hola".substring("a") }) } @@ -36,10 +36,14 @@ describe "strings" { assert.throwsException( { "hola".substring(null, null) }) } - test "substring in second parameter fail" { + test "substring in second parameter should fail" { assert.throwsException({ "hola".substring("a", "e") }) } + test "substring with invalid index should fail" { + assert.throwsException({ "Hola, wollok!".substring(-1, 3) }) + } + test "greater than using null should fail" { assert.throwsException { "hola" > null } } diff --git a/test/sanity/collections/list.wtest b/test/sanity/collections/list.wtest index d51fc7fc..2cb424cb 100644 --- a/test/sanity/collections/list.wtest +++ b/test/sanity/collections/list.wtest @@ -402,4 +402,22 @@ describe "List tests" { assert.equals(#{}, set.difference(randomized)) } + test "findOrElse - happy path" { + var encontro = true + const valueFound = numbers.findOrElse({ elem => elem < 22 }, { encontro = false }) + assert.that(encontro) + } + + test "findOrElse - not found" { + var encontro = true + const valueFound = numbers.findOrElse({ elem => elem > 100 }, { encontro = false }) + assert.notThat(encontro) + } + + test "join" { + assert.equals([1, 2, 3].join("-"), "1-2-3") + assert.equals([].join("-"), "") + } + + } diff --git a/test/sanity/collections/set.wtest b/test/sanity/collections/set.wtest index d5802096..b191c178 100644 --- a/test/sanity/collections/set.wtest +++ b/test/sanity/collections/set.wtest @@ -183,4 +183,34 @@ describe "set tests" { assert.equals(#{22}, numbers) } + test "findOrElse - happy path" { + var encontro = true + const valueFound = #{1, 2, 3, 4}.findOrElse({ elem => elem < 3 }, { encontro = false }) + assert.that(encontro) + } + + test "findOrElse - not found" { + var encontro = true + const valueFound = #{1, 2, 3, 4}.findOrElse({ elem => elem > 100 }, { encontro = false }) + assert.notThat(encontro) + } + + test "max" { + assert.equals(5, #{1, 5, 0, -8, 3}.max()) + assert.equals(5, #{5, 1, 0, -8, 3}.max()) + assert.equals(5, #{1, 0, -8, 3, 5}.max()) + } + + test "clear" { + const unSet = #{1, 2, 3} + assert.equals(3, unSet.size()) + unSet.clear() + assert.equals(#{}, unSet) + } + + test "join" { + assert.equals(#{1, 2, 3}.join("-"), "1-2-3") + assert.equals(#{}.join("-"), "") + } + }