Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 57fef1a2d9
Fetching contributors…

Cannot retrieve contributors at this time

93 lines (84 sloc) 2.17 kb
let assert = require("assert");
extern describe, it, console;
describe('Arrays', function() {
function testElements(int * a, int length) {
for (let int i = 0; i < length; i++) {
a[i] = i;
}
let int sum = 0;
for (let int i = 0; i < length; i++) {
sum += a[i];
}
assert (sum === ((length * (length - 1)) / 2));
}
it('Read / Write from i32 Heap Array', function () {
testElements(new int [1024], 1024);
});
it('Read / Write from i32 Stack Array', function () {
let int a [1024];
testElements(a, 1024);
});
});
describe('Stack Arrays', function() {
it('u8', function () {
let u8 a [1024];
a[42] = 42;
assert (a[42] === 42);
assert (*(a + 42) === 42);
a[42] = 0xFFAD;
assert (*(a + 42) === 0xAD);
a[12] = -1;
assert (a[12] === 255);
});
it('i8', function () {
let i8 a [1024];
a[42] = -42;
assert (a[42] === -42);
assert (*(a + 42) === -42);
*(a + 42) = 0xFFAE;
assert (*(a + 42) === -82);
a[12] = -1;
assert (a[12] === -1);
});
it('1D Array with Initializer', function () {
let int a [4] = [1, 2, 3, 4];
assert (a[0] === 1);
assert (a[1] === 2);
assert (a[2] === 3);
assert (a[3] === 4);
});
it('2D Array with Initializer', function () {
let int a [2][2] = [[1, 2], [3, 4]];
assert (a[0][0] === 1);
assert (a[0][1] === 2);
assert (a[1][0] === 3);
assert (a[1][1] === 4);
});
it('5D Array', function () {
let int a [5][5][5][5][5];
let int x = 0;
for (let int i = 0; i < 5; i++) {
for (let int j = 0; j < 5; j++) {
for (let int k = 0; k < 5; k++) {
for (let int l = 0; l < 5; l++) {
for (let int m = 0; m < 5; m++) {
a[i][j][k][l][m] = x++;
}
}
}
}
}
x = 0;
for (let int i = 0; i < 5; i++) {
for (let int j = 0; j < 5; j++) {
for (let int k = 0; k < 5; k++) {
for (let int l = 0; l < 5; l++) {
for (let int m = 0; m < 5; m++) {
assert (a[i][j][k][l][m] === x++);
}
}
}
}
}
});
});
Jump to Line
Something went wrong with that request. Please try again.