Skip to content
Newer
Older
100644 93 lines (84 sloc) 2.12 KB
e9519ea @mbebenita tests: Rewrote tests to use assert.js instead of should.js.
authored
1 let assert = require("assert");
2
241d48b @mbebenita More test cases.
authored
3 extern describe, it, console;
80652b8 @mbebenita Added mocha test support.
authored
4
5b56f0e @mbebenita Migrated test cases to mocha tests.
authored
5 describe('Arrays', function() {
80652b8 @mbebenita Added mocha test support.
authored
6 function testElements(int * a, int length) {
7 for (let int i = 0; i < length; i++) {
8 a[i] = i;
9 }
10 let int sum = 0;
11 for (let int i = 0; i < length; i++) {
12 sum += a[i];
13 }
e9519ea @mbebenita tests: Rewrote tests to use assert.js instead of should.js.
authored
14 assert (sum === ((length * (length - 1)) / 2));
80652b8 @mbebenita Added mocha test support.
authored
15 }
16
fccd578 @mbebenita More test cases.
authored
17 it('Read / Write from i32 Heap Array', function () {
80652b8 @mbebenita Added mocha test support.
authored
18 testElements(new int [1024], 1024);
19 });
20
fccd578 @mbebenita More test cases.
authored
21 it('Read / Write from i32 Stack Array', function () {
80652b8 @mbebenita Added mocha test support.
authored
22 let int a [1024];
23 testElements(a, 1024);
24 });
241d48b @mbebenita More test cases.
authored
25 });
80652b8 @mbebenita Added mocha test support.
authored
26
241d48b @mbebenita More test cases.
authored
27 describe('Stack Arrays', function() {
28 it('u8', function () {
29 let u8 a [1024];
30 a[42] = 42;
31 assert (a[42] === 42);
32 assert (*(a + 42) === 42);
33 a[42] = 0xFFAD;
34 assert (*(a + 42) === 0xAD);
35 a[12] = -1;
36 assert (a[12] === 255);
37 });
fccd578 @mbebenita More test cases.
authored
38
241d48b @mbebenita More test cases.
authored
39 it('i8', function () {
40 let i8 a [1024];
41 a[42] = -42;
42 assert (a[42] === -42);
43 assert (*(a + 42) === -42);
44 *(a + 42) = 0xFFAE;
45 assert (*(a + 42) === -82);
46 a[12] = -1;
47 assert (a[12] === -1);
48 });
fccd578 @mbebenita More test cases.
authored
49
50 it('1D Array with Initializer', function () {
51 let int a [4] = [1, 2, 3, 4];
52 assert (a[0] === 1);
53 assert (a[1] === 2);
54 assert (a[2] === 3);
55 assert (a[3] === 4);
56 });
57
58 it('2D Array with Initializer', function () {
59 let int a [2][2] = [[1, 2], [3, 4]];
60 assert (a[0][0] === 1);
61 assert (a[0][1] === 2);
62 assert (a[1][0] === 3);
63 assert (a[1][1] === 4);
64 });
65
66 it('5D Array', function () {
67 let int a [5][5][5][5][5];
68 let int x = 0;
69 for (let int i = 0; i < 5; i++) {
70 for (let int j = 0; j < 5; j++) {
71 for (let int k = 0; k < 5; k++) {
72 for (let int l = 0; l < 5; l++) {
73 for (let int m = 0; m < 5; m++) {
74 a[i][j][k][l][m] = x++;
75 }
76 }
77 }
78 }
79 }
80 x = 0;
81 for (let int i = 0; i < 5; i++) {
82 for (let int j = 0; j < 5; j++) {
83 for (let int k = 0; k < 5; k++) {
84 for (let int l = 0; l < 5; l++) {
85 for (let int m = 0; m < 5; m++) {
86 assert (a[i][j][k][l][m] === x++);
87 }
88 }
89 }
90 }
91 }
92 });
241d48b @mbebenita More test cases.
authored
93 });
Something went wrong with that request. Please try again.