Reworked dot.toy into a proper test

This commit is contained in:
2022-09-04 10:37:19 +01:00
parent 6787cfff55
commit cc27da50df
2 changed files with 11 additions and 13 deletions

View File

@@ -1,26 +1,16 @@
/*
//dot product //dot product
var a = [1, 2, 3]; var a = [1, 2, 3];
var b = [4, 5, 6]; var b = [4, 5, 6];
assert _length(a) == _length(b), "lengths wrong"; assert _length(a) == _length(b), "a and b lengths are wrong";
var acc = 0; var acc = 0;
for (var i = 0; i < _length(a); i++) { for (var i = 0; i < _length(a); i++) {
acc += _get(a, i) * _get(b, i); acc += _get(a, i) * _get(b, i);
} }
print acc; assert acc == 32, "dot product failed";
*/
//matrix multiply
var c = [[4], [5], [6]]; //this is going t obe a 3x1
var d = [[1, 2, 3]]; //this is going to be a 1x3
// c x d = 3x3
// d x c = 1x1
//assume the args are matrices //assume the args are matrices
fn matrix(first, second) { fn matrix(first, second) {
@@ -66,6 +56,13 @@ fn matrix(first, second) {
return result; return result;
} }
//matrix multiply
var c = [[4], [5], [6]]; //this is a 3x1
var d = [[1, 2, 3]]; //this is a 1x3
// c x d = 3x3
// d x c = 1x1
assert matrix(c, d) == [[4,8,12],[5,10,15],[6,12,18]], "Matrix multiplication failed"; assert matrix(c, d) == [[4,8,12],[5,10,15],[6,12,18]], "Matrix multiplication failed";
print "All good"; print "All good";

View File

@@ -150,11 +150,12 @@ int main() {
{ {
//run each file in ../scripts/test/ //run each file in ../scripts/test/
int count = 13; int count = 14;
char* filenames[] = { char* filenames[] = {
"arithmetic.toy", "arithmetic.toy",
"casting.toy", "casting.toy",
"comparisons.toy", "comparisons.toy",
"dot-and-matrix.toy",
"functions.toy", "functions.toy",
"jumps.toy", "jumps.toy",
"jumps-in-functions.toy", "jumps-in-functions.toy",