import { assert, assertEquals } from "https://deno.land/std@0.102.0/testing/asserts.ts"; import { default as M } from "./m.js"; Deno.test("Iterate.New", ()=> { let dimensions = 3; let count = 4; let cloud = M.Iterate.New(dimensions, count, (i, j)=>i+j); assertEquals(cloud.length, count, "correct count"); assertEquals(cloud[0].length, dimensions, "correct dimensions"); assertEquals(cloud[0][0], 0); assertEquals(cloud[3][2], 5, "correct output"); }); Deno.test("Create.Box", ()=> { let min = [-1, -2, -3]; let max = [1, 2, 3]; let count = 10; let box = M.Create.Box(min, max, count); assertEquals(box.length, count, "correct count"); for(let i=0; i= min[j], true); assert(box[i][j] <= max[j], true, "correct range"); } } }); Deno.test("Create.Transpose", ()=> { let v1 = [1, 2, 3]; let v2 = [4, 5, 6]; let tpose = M.Create.Transpose([v1, v2]); assertEquals(tpose.length, 3, "correct count"); assertEquals(tpose[0].length, 2, "correct dimensions"); assertEquals(tpose[0][0], v1[0]); assertEquals(tpose[0][1], v2[0], "correct placement"); }); Deno.test("Create.Outer", ()=> { let v1 = [1, 2, 3]; let v2 = [4, 5]; let outer = M.Create.Outer(v1, v2); assertEquals(outer.length, v2.length, "correct count"); assertEquals(outer[0].length, v1.length, "correct dimensions"); assertEquals(outer[1][0], v1[0]*v2[1], "correct placement") }); Deno.test("Create.Clone", ()=> { let v1 = [1, 2, 3]; let v2 = [4, 5, 6]; let clone = M.Create.Clone([v1, v2]); assertEquals(clone.length, 2, "correct count"); assertEquals(clone[0].length, v1.length, "correct dimensions"); assertEquals(clone[1][0], v2[0], "correct placement"); }); Deno.test("Mutate.Pad", ()=> { let matrix = [ [1, 2, 3], [4, 5, 6] ]; M.Mutate.Pad(matrix); assertEquals(matrix.length, 2, "correct count"); assertEquals(matrix[0].length, 4, "correct dimensions"); assertEquals(matrix[0][3], 1, "correct placement"); }); Deno.test("Mutate.Unpad", ()=> { let matrix = [ [1, 2, 3, 1], [4, 5, 6, 1] ]; M.Mutate.Unpad(matrix); assertEquals(matrix.length, 2, "correct count"); assertEquals(matrix[0].length, 3, "correct dimensions"); assertEquals(matrix[1][0], 4, "correct placement"); }); Deno.test("Single.Affine", ()=> { let v = [1, 2]; let m = [[0.1, 0.2], [0.3, 0.4]]; let t = M.Single.Affine(v, m); assertEquals(t.length, 2, "correct dimensions"); assertEquals(t[0], 0.5) assertEquals(t[1], 1.1, "correct placement"); }); Deno.test("Batch.Affine", ()=> { let c = [[1, 2], [3, 4]]; let m = [[0.1, 0.2], [0.3, 0.4]]; let t = M.Batch.Affine(c, m); assertEquals(t.length, 2, "correct count"); assertEquals(t[0].length, 2, "correct dimensions") assertEquals(t[0][1], 1.1, "correct placement"); });