From cc27da50dfcc7f698c86fea72cde054d0e33fa62 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 4 Sep 2022 10:37:19 +0100 Subject: [PATCH] Reworked dot.toy into a proper test --- scripts/{dot.toy => test/dot-and-matrix.toy} | 21 +++++++++----------- test/test_interpreter.c | 3 ++- 2 files changed, 11 insertions(+), 13 deletions(-) rename scripts/{dot.toy => test/dot-and-matrix.toy} (87%) diff --git a/scripts/dot.toy b/scripts/test/dot-and-matrix.toy similarity index 87% rename from scripts/dot.toy rename to scripts/test/dot-and-matrix.toy index 7a8effd..23126f9 100644 --- a/scripts/dot.toy +++ b/scripts/test/dot-and-matrix.toy @@ -1,26 +1,16 @@ -/* - //dot product var a = [1, 2, 3]; 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; for (var i = 0; i < _length(a); 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 fn matrix(first, second) { @@ -66,6 +56,13 @@ fn matrix(first, second) { 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"; print "All good"; \ No newline at end of file diff --git a/test/test_interpreter.c b/test/test_interpreter.c index d1955ce..f2df14e 100644 --- a/test/test_interpreter.c +++ b/test/test_interpreter.c @@ -150,11 +150,12 @@ int main() { { //run each file in ../scripts/test/ - int count = 13; + int count = 14; char* filenames[] = { "arithmetic.toy", "casting.toy", "comparisons.toy", + "dot-and-matrix.toy", "functions.toy", "jumps.toy", "jumps-in-functions.toy",