Revised tests

This commit is contained in:
2026-05-30 10:53:21 +10:00
parent 75cb1dfa86
commit d194bff5fe
36 changed files with 266 additions and 199 deletions
+46
View File
@@ -0,0 +1,46 @@
//1-D array
{
var array: Array = [1, 2, 3];
array[1] = 6;
assert array == [1, 6, 3], "1-D array failed";
}
//we need to go deeper
{
var array = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
array[1][1] = 99;
assert array == [[1, 2, 3],[4,99,6],[7,8,9]], "2-D array failed";
}
//attributes
{
var array = [0,1,2,3,4,5,6,7,8,9];
assert array.length == 10, "Array length attribute failed";
array.pushBack(10);
assert array.length == 11, "Array pushBack attribute failed";
array.popBack();
array.popBack();
assert array.popBack() == 8, "Array popBack attribute failed";
}
//sorting algorithm
{
//WARN: Array sorting algorithm not yet implemented
}
//syntax
{
var empty = [];
assert empty.length == 0, "Empty array failed";
var trailing = [1, 2, 3, ];
assert trailing == [1,2,3], "Trailing comma array failed";
}
+55
View File
@@ -0,0 +1,55 @@
//define and invoke a function
{
fn greeting() {
return "Hello world";
}
assert greeting() == "Hello world", "Function definition failed";
}
//functions within other function argument lists
{
fn outer(arg: String) {
return arg == "Hello world";
}
fn inner() {
return "Hello world";
}
assert outer(inner()), "Functions within argument lists failed";
}
//first class functions
{
fn hello() {
print "Hello world";
}
fn identity(x) {
return x;
}
assert identity(hello) == hello, "First class functions failed";
}
//closures
{
//closures
fn makeCounter() {
var counter: Int = 0;
fn increment() {
return ++counter;
}
return increment;
}
var tally: Function = makeCounter();
tally();
tally();
tally();
assert tally() == 4, "closures failed";
}
+27
View File
@@ -0,0 +1,27 @@
//declare, define and manipulate strings
{
var string: String = "Hello World";
assert string[5] == " ", "String indexing failed";
var greeting: String = string[0:5];
assert greeting == "Hello", "String slicing failed";
var parting: String = "Goodbye " .. string[6:5];
print parting;
assert parting == "Goodbye World", "String concat from an index failed";
//WARN: Unbounded slice not possible without indexing from the end of a string
//var simple: String = parting[5:-1];
//assert simple == "bye World", "String unbounded slice failed";
}
//var greeting: String = "Hello World";
//var parting: String = "Goodbye " .. greeting[6:5];
//String attributes
{
var string: String = "Hello World";
assert string.length == 11, "string.length failed";
assert string.asUpper == "HELLO WORLD", "string.asUpper failed";
assert string.asLower == "hello world", "string.asLower failed";
}
+33
View File
@@ -0,0 +1,33 @@
//1-D table
{
var table: Table = ["alpha": 1, "beta": 2, "gamma": 3];
table["beta"] = 6;
assert table == ["alpha": 1, "beta": 6, "gamma": 3], "1-D tables failed";
}
//nested
{
var table: Table = [
"outer": ["inner": true],
"alpha": 1,
"beta": 2,
"gamma": 3
];
assert table == ["alpha": 1, "beta": 2, "gamma": 3, "outer": ["inner": true]], "nested tables failed";
}
//syntax
{
var empty = [:];
assert empty.length == 0, "Empty table failed";
var trailing = [
"alpha":1,
"beta":2,
"gamma":3,
];
assert trailing == ["alpha": 1, "beta": 2, "gamma": 3], "Trailing comma table failed";
}