forked from mbebenita/LLJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.ljs
60 lines (45 loc) · 1.22 KB
/
matrix.ljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
let assert = require("assert");
extern describe, it, console;
struct Matrix {
float elements[2][2];
static function mul(Matrix * a, Matrix * b, Matrix * c) {
for (let int j = 0; j < 2; j++) {
for (let int k = 0; k < 2; k++) {
for (let int i = 0; i < 2; i++) {
c->elements[i][j] += a->elements[i][k] * b->elements[k][j];
}
}
}
}
}
describe('Matrix', function() {
it('Multiply', function () {
let Matrix a, b, c, d;
a.elements[0][0] = 1;
a.elements[0][1] = 2;
a.elements[1][0] = 3;
a.elements[1][1] = 4;
b.elements[0][0] = 0;
b.elements[0][1] = 0;
b.elements[1][0] = 0;
b.elements[1][1] = 0;
c.elements[0][0] = 0;
c.elements[0][1] = 0;
c.elements[1][0] = 0;
c.elements[1][1] = 0;
Matrix.mul(&a, &a, &b);
assert (b.elements[0][0] === 7);
assert (b.elements[0][1] === 10);
assert (b.elements[1][0] === 15);
assert (b.elements[1][1] === 22);
Matrix.mul(&a, &b, &c);
assert (c.elements[0][0] === 37);
assert (c.elements[0][1] === 54);
assert (c.elements[1][0] === 81);
assert (c.elements[1][1] === 118);
});
});
describe('Structs', function() {
it('allocates an union', function () {
});
});