Skip to content

Commit

Permalink
Migrated test cases to mocha tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbebenita committed Jul 26, 2012
1 parent 80652b8 commit 5b56f0e
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 133 deletions.
6 changes: 0 additions & 6 deletions src/tests/arrays.ljs

This file was deleted.

74 changes: 0 additions & 74 deletions src/tests/stack_arrays.ljs

This file was deleted.

24 changes: 0 additions & 24 deletions src/tests/struct-1.ljs

This file was deleted.

25 changes: 0 additions & 25 deletions src/tests/union-0.ljs

This file was deleted.

63 changes: 63 additions & 0 deletions test/arrays-stack.ljs
@@ -0,0 +1,63 @@
extern describe, it;

struct ST {
int x;
};

struct InlineArrayST {
int arr[100];
};

struct InlineStructArrayST {
InlineArrayST arr[100];
};

describe('Arrays-Stack', function () {
it('allocates an int array on the stack', function () {
let int arr[100];
arr[0] = 5;
arr[1] = 10;

(*arr).should.equal(5);
(arr[0]).should.equal(5);
(arr[1]).should.equal(10);

let ST s;
(&s-arr).should.equal(100);
});

it('allocates an u8 array on the stack', function () {
let u8 arr[100];
arr[0] = 5;
arr[1] = 10;
(*arr).should.equal(5, "dereferencing array");
(arr[0]).should.equal(5, "access first element");
(arr[1]).should.equal(10, "access second element");

let float arr2[100];
arr2[0] = 5;
arr2[1] = 10;
(*arr2).should.equal(5);
(arr2[0]).should.equal(5);
(arr2[1]).should.equal(10);

let ST s;
(&s-arr).should.equal(126);
});

it('allocates a struct with an inline array', function () {
let InlineArrayST s;
s.arr[5] = 10;

let ST s2;
(&s2-&s).should.equal(100);
});

it('allocates a struct with an inline array of structs with arrays', function () {
let InlineStructArrayST s;
s.arr[5].arr[5] = 5;

let ST s2;
(&s2-&s).should.equal(100*100);
});
});
5 changes: 1 addition & 4 deletions test/array-0.ljs → test/arrays.ljs
@@ -1,9 +1,6 @@
extern describe, it; extern describe, it;
extern Number;


let assert = require("assert"); describe('Arrays', function() {

describe('Array 0', function() {
function testElements(int * a, int length) { function testElements(int * a, int length) {
for (let int i = 0; i < length; i++) { for (let int i = 0; i < length; i++) {
a[i] = i; a[i] = i;
Expand Down
60 changes: 60 additions & 0 deletions test/structs.ljs
@@ -0,0 +1,60 @@
extern describe, it;

struct S {
union {
int x;
float y;
} u;
struct {
int x;
float y;
} s;
int x;
};

function floatIsEqual(a, b) {
let d = a - b;
if (d < 0) {
d *= -1;
}
return d < 0.001;
}

describe('Structs', function() {
it('allocates a struct with unions', function () {
let S s;
s.u.x = 5;
s.s.x = 5;
s.s.y = 3.14;
s.x = 10;

(s.u.x).should.equal(5);
(s.u.y).should.equal(7.006492321624085e-45);
(s.s.x).should.equal(5);
floatIsEqual(s.s.y, 3.14).should.be.true;
(s.x).should.equal(10);
});
});

union foo {
int x;
float y;
};

struct bar {
foo u;
};

describe('Structs', function() {
it('allocates an union', function () {
let foo u;
u.x = 5;
(u.x).should.equal(5);
(floatIsEqual(u.y, 7.006492321624085e-45)).should.be.true

let foo *uStar = new foo;
uStar->x = 5;
(uStar->x).should.equal(5);
(floatIsEqual(uStar->y, 7.006492321624085e-45)).should.be.true
});
});

0 comments on commit 5b56f0e

Please sign in to comment.