refactor: move benchmark directory under test and update all references
The benchmark directory is relocated from the project root into the test directory, and all scripts, documentation links, and gitignore paths are updated accordingly. The test runner is also refactored to explicitly walk subdirectories (core, io, language, limit) instead of using a single test root, and a new test/README.md is added to document the test suite structure. Additionally, the constructor test for the Foo class is updated to add a zero-arity constructor and adjust expected output strings.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
var a = [1]
|
||||
a.add(2)
|
||||
IO.print(a) // expect: [1, 2]
|
||||
a.add(3)
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
|
||||
// Returns added element.
|
||||
IO.print(a.add(4)) // expect: 4
|
||||
@@ -0,0 +1,11 @@
|
||||
var a = [1]
|
||||
a.addAll([2, 3])
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
a.addAll([])
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
a.addAll(4..6)
|
||||
IO.print(a) // expect: [1, 2, 3, 4, 5, 6]
|
||||
|
||||
// Returns argument.
|
||||
var range = 7..9
|
||||
IO.print(a.addAll(range) == range) // expect: true
|
||||
@@ -0,0 +1,9 @@
|
||||
var a = [1, 2, 3]
|
||||
var b = a.all {|x| x > 1 }
|
||||
IO.print(b) // expect: false
|
||||
|
||||
var d = a.all {|x| x > 0 }
|
||||
IO.print(d) // expect: true
|
||||
|
||||
var e = [].all {|x| false }
|
||||
IO.print(e) // expect: true
|
||||
@@ -0,0 +1 @@
|
||||
IO.print([1, 2, 3].all {|x| "truthy" }) // expect: true
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].all("string") // expect runtime error: String does not implement 'call(_)'.
|
||||
@@ -0,0 +1,10 @@
|
||||
var a = [1, 2, 3]
|
||||
|
||||
var b = a.any {|x| x > 3 }
|
||||
IO.print(b) // expect: false
|
||||
|
||||
var d = a.any {|x| x > 1 }
|
||||
IO.print(d) // expect: true
|
||||
|
||||
var e = [].any {|x| true }
|
||||
IO.print(e) // expect: false
|
||||
@@ -0,0 +1 @@
|
||||
IO.print([1, 2, 3].any {|x| "truthy" }) // expect: true
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].any("string") // expect runtime error: String does not implement 'call(_)'.
|
||||
@@ -0,0 +1,7 @@
|
||||
var a = [1, 2, 3]
|
||||
a.clear()
|
||||
IO.print(a) // expect: []
|
||||
IO.print(a.count) // expect: 0
|
||||
|
||||
// Returns null.
|
||||
IO.print([1, 2].clear()) // expect: null
|
||||
@@ -0,0 +1,3 @@
|
||||
IO.print([].count) // expect: 0
|
||||
IO.print([1].count) // expect: 1
|
||||
IO.print([1, 2, 3, 4].count) // expect: 4
|
||||
@@ -0,0 +1,41 @@
|
||||
// Add to empty list.
|
||||
var a = []
|
||||
a.insert(1, 0)
|
||||
IO.print(a) // expect: [1]
|
||||
|
||||
// Normal indices.
|
||||
var b = [1, 2, 3]
|
||||
b.insert(4, 0)
|
||||
IO.print(b) // expect: [4, 1, 2, 3]
|
||||
|
||||
var c = [1, 2, 3]
|
||||
c.insert(4, 1)
|
||||
IO.print(c) // expect: [1, 4, 2, 3]
|
||||
|
||||
var d = [1, 2, 3]
|
||||
d.insert(4, 2)
|
||||
IO.print(d) // expect: [1, 2, 4, 3]
|
||||
|
||||
var e = [1, 2, 3]
|
||||
e.insert(4, 3)
|
||||
IO.print(e) // expect: [1, 2, 3, 4]
|
||||
|
||||
// Negative indices.
|
||||
var f = [1, 2, 3]
|
||||
f.insert(4, -4)
|
||||
IO.print(f) // expect: [4, 1, 2, 3]
|
||||
|
||||
var g = [1, 2, 3]
|
||||
g.insert(4, -3)
|
||||
IO.print(g) // expect: [1, 4, 2, 3]
|
||||
|
||||
var h = [1, 2, 3]
|
||||
h.insert(4, -2)
|
||||
IO.print(h) // expect: [1, 2, 4, 3]
|
||||
|
||||
var i = [1, 2, 3]
|
||||
i.insert(4, -1)
|
||||
IO.print(i) // expect: [1, 2, 3, 4]
|
||||
|
||||
// Returns.inserted value.
|
||||
IO.print([1, 2].insert(3, 0)) // expect: 3
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.insert("value", 1.5) // expect runtime error: Index must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.insert("value", "2") // expect runtime error: Index must be a number.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.insert("value", 4) // expect runtime error: Index out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.insert("value", -5) // expect runtime error: Index out of bounds.
|
||||
@@ -0,0 +1,13 @@
|
||||
var a = ["one", "two", "three", "four"]
|
||||
IO.print(a.iterate(null)) // expect: 0
|
||||
IO.print(a.iterate(0)) // expect: 1
|
||||
IO.print(a.iterate(1)) // expect: 2
|
||||
IO.print(a.iterate(2)) // expect: 3
|
||||
IO.print(a.iterate(3)) // expect: false
|
||||
|
||||
// Out of bounds.
|
||||
IO.print(a.iterate(123)) // expect: false
|
||||
IO.print(a.iterate(-1)) // expect: false
|
||||
|
||||
// Nothing to iterate in an empty list.
|
||||
IO.print([].iterate(null)) // expect: false
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.iterate(1.5) // expect runtime error: Iterator must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.iterate("2") // expect runtime error: Iterator must be a number.
|
||||
@@ -0,0 +1,5 @@
|
||||
var a = ["one", "two", "three", "four"]
|
||||
IO.print(a.iteratorValue(0)) // expect: one
|
||||
IO.print(a.iteratorValue(1)) // expect: two
|
||||
IO.print(a.iteratorValue(2)) // expect: three
|
||||
IO.print(a.iteratorValue(3)) // expect: four
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.iteratorValue(1.5) // expect runtime error: Iterator must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.iteratorValue("2") // expect runtime error: Iterator must be a number.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.iteratorValue(4) // expect runtime error: Iterator out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.iteratorValue(-5) // expect runtime error: Iterator out of bounds.
|
||||
@@ -0,0 +1,23 @@
|
||||
// Handle empty list.
|
||||
IO.print([].join(",") == "") // expect: true
|
||||
|
||||
// Handle a simple list with an empty delimeter.
|
||||
IO.print([1, 2, 3].join("")) // expect: 123
|
||||
|
||||
// Handle a simple list with no separator.
|
||||
IO.print([1, 2, 3].join) // expect: 123
|
||||
|
||||
// Does not quote strings.
|
||||
IO.print([1, "2", true].join(",")) // expect: 1,2,true
|
||||
|
||||
// Nested lists.
|
||||
IO.print([1, [2, [3], 4], 5].join(",")) // expect: 1,[2, [3], 4],5
|
||||
|
||||
// Calls toString on elements.
|
||||
class Foo {
|
||||
toString { "Foo.toString" }
|
||||
}
|
||||
|
||||
IO.print([1, new Foo, 2].join(", ")) // expect: 1, Foo.toString, 2
|
||||
|
||||
// TODO: Handle lists that contain themselves.
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].join(2) // expect runtime error: Right operand must be a string.
|
||||
@@ -0,0 +1,3 @@
|
||||
var a = [1, 2, 3]
|
||||
var b = a.map {|x| x + 1 }
|
||||
IO.print(b) // expect: [2, 3, 4]
|
||||
@@ -0,0 +1,6 @@
|
||||
var list = new List
|
||||
|
||||
IO.print(list.count) // expect: 0
|
||||
IO.print(list) // expect: []
|
||||
list.add(1)
|
||||
IO.print(list) // expect: [1]
|
||||
@@ -0,0 +1,2 @@
|
||||
IO.print(![1, 2]) // expect: false
|
||||
IO.print(![]) // expect: false
|
||||
@@ -0,0 +1,18 @@
|
||||
var a = [1, 2, 3]
|
||||
var b = [4, 5, 6]
|
||||
var c = a + b
|
||||
var d = a + (4..6)
|
||||
var e = a + []
|
||||
var f = [] + a
|
||||
var g = [] + []
|
||||
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
IO.print(b) // expect: [4, 5, 6]
|
||||
IO.print(c) // expect: [1, 2, 3, 4, 5, 6]
|
||||
IO.print(d) // expect: [1, 2, 3, 4, 5, 6]
|
||||
IO.print(e) // expect: [1, 2, 3]
|
||||
IO.print(f) // expect: [1, 2, 3]
|
||||
IO.print(g) // expect: []
|
||||
|
||||
// Doesn't modify original list.
|
||||
IO.print(a) // expect: [1, 2, 3]
|
||||
@@ -0,0 +1,14 @@
|
||||
var a = [1, 4, 2, 1, 5]
|
||||
var b = ["W", "o", "r", "l", "d"]
|
||||
var max = new Fn {|a, b| a > b ? a : b }
|
||||
var sum = new Fn {|a, b| a + b }
|
||||
|
||||
IO.print(a.reduce(max)) // expect: 5
|
||||
IO.print(a.reduce(10, max)) // expect: 10
|
||||
|
||||
IO.print(a.reduce(sum)) // expect: 13
|
||||
IO.print(a.reduce(-1, sum)) // expect: 12
|
||||
|
||||
// sum also concatenates strings
|
||||
IO.print(b.reduce("Hello ", sum)) // expect: Hello World
|
||||
IO.print(b.reduce(sum)) // expect: World
|
||||
@@ -0,0 +1 @@
|
||||
[].reduce {|a, b| 1 } // expect runtime error: Can't reduce an empty sequence.
|
||||
@@ -0,0 +1,2 @@
|
||||
IO.print([1].reduce {|a, b| 42 }) // expect: 1
|
||||
IO.print([].reduce(1) {|a, b| 42 }) // expect: 1
|
||||
@@ -0,0 +1 @@
|
||||
[1, 2, 3].reduce {|x, y, z| x } // expect runtime error: Function expects more arguments.
|
||||
@@ -0,0 +1,27 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt(0)
|
||||
IO.print(a) // expect: [2, 3]
|
||||
|
||||
var b = [1, 2, 3]
|
||||
b.removeAt(1)
|
||||
IO.print(b) // expect: [1, 3]
|
||||
|
||||
var c = [1, 2, 3]
|
||||
c.removeAt(2)
|
||||
IO.print(c) // expect: [1, 2]
|
||||
|
||||
// Index backwards from end.
|
||||
var d = [1, 2, 3]
|
||||
d.removeAt(-3)
|
||||
IO.print(d) // expect: [2, 3]
|
||||
|
||||
var e = [1, 2, 3]
|
||||
e.removeAt(-2)
|
||||
IO.print(e) // expect: [1, 3]
|
||||
|
||||
var f = [1, 2, 3]
|
||||
f.removeAt(-1)
|
||||
IO.print(f) // expect: [1, 2]
|
||||
|
||||
// Return the removed value.
|
||||
IO.print([3, 4, 5].removeAt(1)) // expect: 4
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt(1.5) // expect runtime error: Index must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt("2") // expect runtime error: Index must be a number.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt(4) // expect runtime error: Index out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a.removeAt(-5) // expect runtime error: Index out of bounds.
|
||||
@@ -0,0 +1,12 @@
|
||||
// Returns elements.
|
||||
var list = ["a", "b", "c", "d"]
|
||||
IO.print(list[0]) // expect: a
|
||||
IO.print(list[1]) // expect: b
|
||||
IO.print(list[2]) // expect: c
|
||||
IO.print(list[3]) // expect: d
|
||||
|
||||
// Allows indexing backwards from the end.
|
||||
IO.print(list[-4]) // expect: a
|
||||
IO.print(list[-3]) // expect: b
|
||||
IO.print(list[-2]) // expect: c
|
||||
IO.print(list[-1]) // expect: d
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[1.5] // expect runtime error: Subscript must be an integer.
|
||||
@@ -0,0 +1,35 @@
|
||||
// Returns lists.
|
||||
var list = ["a", "b", "c", "d", "e"]
|
||||
IO.print(list[0..0]) // expect: [a]
|
||||
IO.print(list[1...1]) // expect: []
|
||||
IO.print(list[1..2]) // expect: [b, c]
|
||||
IO.print(list[1...2]) // expect: [b]
|
||||
IO.print(list[2..4]) // expect: [c, d, e]
|
||||
IO.print(list[2...5]) // expect: [c, d, e]
|
||||
|
||||
// A backwards range reverses.
|
||||
IO.print(list[3..1]) // expect: [d, c, b]
|
||||
IO.print(list[3...1]) // expect: [d, c]
|
||||
IO.print(list[3...3]) // expect: []
|
||||
|
||||
// Negative ranges index from the end.
|
||||
IO.print(list[-5..-2]) // expect: [a, b, c, d]
|
||||
IO.print(list[-5...-2]) // expect: [a, b, c]
|
||||
IO.print(list[-3..-5]) // expect: [c, b, a]
|
||||
IO.print(list[-3...-6]) // expect: [c, b, a]
|
||||
|
||||
// Half-negative ranges are treated like the negative value is fixed before
|
||||
// walking the range.
|
||||
IO.print(list[-5..3]) // expect: [a, b, c, d]
|
||||
IO.print(list[-3...5]) // expect: [c, d, e]
|
||||
IO.print(list[-2..1]) // expect: [d, c, b]
|
||||
IO.print(list[-2...0]) // expect: [d, c, b]
|
||||
|
||||
IO.print(list[1..-2]) // expect: [b, c, d]
|
||||
IO.print(list[2...-1]) // expect: [c, d]
|
||||
IO.print(list[4..-5]) // expect: [e, d, c, b, a]
|
||||
IO.print(list[3...-6]) // expect: [d, c, b, a]
|
||||
|
||||
// An empty range at zero is allowed on an empty list.
|
||||
IO.print([][0...0]) // expect: []
|
||||
IO.print([][0..-1]) // expect: []
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[1.5..2] // expect runtime error: Range start must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[3..2] // expect runtime error: Range start out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[-4..2] // expect runtime error: Range start out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[1...4] // expect runtime error: Range end out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[0...-5] // expect runtime error: Range end out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[1..2.5] // expect runtime error: Range end must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[1..3] // expect runtime error: Range end out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[0..-4] // expect runtime error: Range end out of bounds.
|
||||
@@ -0,0 +1,23 @@
|
||||
// Basic assignment.
|
||||
{
|
||||
var list = [1, 2, 3]
|
||||
list[0] = 5
|
||||
list[1] = 6
|
||||
list[2] = 7
|
||||
IO.print(list) // expect: [5, 6, 7]
|
||||
}
|
||||
|
||||
// Returns right-hand side.
|
||||
{
|
||||
var list = [1, 2, 3]
|
||||
IO.print(list[1] = 5) // expect: 5
|
||||
}
|
||||
|
||||
// Negative indices.
|
||||
{
|
||||
var list = [1, 2, 3]
|
||||
list[-1] = 5
|
||||
list[-2] = 6
|
||||
list[-3] = 7
|
||||
IO.print(list) // expect: [7, 6, 5]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[1.5] = 1 // expect runtime error: Subscript must be an integer.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a["2"] = 1 // expect runtime error: Subscript must be a number.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[4] = 1 // expect runtime error: Subscript out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[-5] = 1 // expect runtime error: Subscript out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[4] // expect runtime error: Subscript out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a[-5] // expect runtime error: Subscript out of bounds.
|
||||
@@ -0,0 +1,2 @@
|
||||
var a = [1, 2, 3]
|
||||
a["2"] // expect runtime error: Subscript must be a number or a range.
|
||||
@@ -0,0 +1,17 @@
|
||||
// Handle empty list.
|
||||
IO.print([].toString) // expect: []
|
||||
|
||||
// Does not quote strings.
|
||||
IO.print([1, "2", true].toString) // expect: [1, 2, true]
|
||||
|
||||
// Nested lists.
|
||||
IO.print([1, [2, [3], 4], 5]) // expect: [1, [2, [3], 4], 5]
|
||||
|
||||
// Calls toString on elements.
|
||||
class Foo {
|
||||
toString { "Foo.toString" }
|
||||
}
|
||||
|
||||
IO.print([1, new Foo, 2]) // expect: [1, Foo.toString, 2]
|
||||
|
||||
// TODO: Handle lists that contain themselves.
|
||||
@@ -0,0 +1,5 @@
|
||||
IO.print([] is List) // expect: true
|
||||
IO.print([] is Sequence) // expect: true
|
||||
IO.print([] is Object) // expect: true
|
||||
IO.print([] is Bool) // expect: false
|
||||
IO.print([].type == List) // expect: true
|
||||
@@ -0,0 +1,6 @@
|
||||
var a = [1, 2, 3]
|
||||
var b = a.where {|x| x > 1 }
|
||||
IO.print(b) // expect: [2, 3]
|
||||
|
||||
var c = a.where {|x| x > 10 }
|
||||
IO.print(c) // expect: []
|
||||
Reference in New Issue
Block a user