From 817165a8333d30bc5c807efc8335cc20f23dc26a Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Tue, 26 Oct 2021 23:26:03 -0400 Subject: [PATCH] adjust tests --- tests/test_coords.scad | 2 +- tests/test_linalg.scad | 43 +++++++++++++++++++++++++++++++++++++++++ tests/test_math.scad | 38 ------------------------------------ tests/test_vectors.scad | 4 ++-- 4 files changed, 46 insertions(+), 41 deletions(-) diff --git a/tests/test_coords.scad b/tests/test_coords.scad index 0022efa..e0d4f17 100644 --- a/tests/test_coords.scad +++ b/tests/test_coords.scad @@ -111,7 +111,7 @@ module test_lift_plane() { assert_approx(project_plane([[1,1,1],[3,1,3],[1,1,4]]),[[-1/sqrt(2),1/sqrt(2),0,0],[0,0,1,-1],[1/sqrt(2),1/sqrt(2),0,-sqrt(2)],[0,0,0,1]]); N=30; - data2 = array_group(rands(0,10,3*N,seed=77),3); + data2 = list_to_matrix(rands(0,10,3*N,seed=77),3); data3 = [for (d=data2) [d.x,d.y,d.x*3+d.y*5+2]]; planept = select(data3,0,N-4); testpt = select(data3, N-3,-1); diff --git a/tests/test_linalg.scad b/tests/test_linalg.scad index bfde6d7..08f2060 100644 --- a/tests/test_linalg.scad +++ b/tests/test_linalg.scad @@ -154,6 +154,49 @@ module test_null_space(){ test_null_space(); + + + +module test_back_substitute(){ + R = [[12,4,3,2], + [0,2,-4,2], + [0,0,4,5], + [0,0,0,15]]; + assert_approx(back_substitute(R, [1,2,3,3]), [-0.675, 1.8, 0.5, 0.2]); + assert_approx(back_substitute(R, [6, 3, 3.5, 37], transpose=true), [0.5, 0.5, 1, 2]); + assert_approx(back_substitute(R, [[38,101],[-6,-16], [31, 71], [45, 105]]), [[1, 4],[2,3],[4,9],[3,7]]); + assert_approx(back_substitute(R, [[12,48],[8,22],[11,36],[71,164]],transpose=true), [[1, 4],[2,3],[4,9],[3,7]]); + assert_approx(back_substitute([[2]], [4]), [2]); + sing1 =[[0,4,3,2], + [0,3,-4,2], + [0,0,4,5], + [0,0,0,15]]; + sing2 =[[12,4,3,2], + [0,0,-4,2], + [0,0,4,5], + [0,0,0,15]]; + sing3 = [[12,4,3,2], + [0,2,-4,2], + [0,0,4,5], + [0,0,0,0]]; + assert_approx(back_substitute(sing1, [1,2,3,4]), []); + assert_approx(back_substitute(sing2, [1,2,3,4]), []); + assert_approx(back_substitute(sing3, [1,2,3,4]), []); +} +test_back_substitute(); + + + + + +module test_outer_product(){ + assert_equal(outer_product([1,2,3],[4,5,6]), [[4,5,6],[8,10,12],[12,15,18]]); + assert_equal(outer_product([1,2],[4,5,6]), [[4,5,6],[8,10,12]]); + assert_equal(outer_product([9],[7]), [[63]]); +} +test_outer_product(); + + module test_column() { v = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]; assert(column(v,2) == [3, 7, 11, 15]); diff --git a/tests/test_math.scad b/tests/test_math.scad index 6ad4129..710762d 100644 --- a/tests/test_math.scad +++ b/tests/test_math.scad @@ -775,36 +775,6 @@ module test_c_norm(){ } test_c_norm(); -module test_back_substitute(){ - R = [[12,4,3,2], - [0,2,-4,2], - [0,0,4,5], - [0,0,0,15]]; - assert_approx(back_substitute(R, [1,2,3,3]), [-0.675, 1.8, 0.5, 0.2]); - assert_approx(back_substitute(R, [6, 3, 3.5, 37], transpose=true), [0.5, 0.5, 1, 2]); - assert_approx(back_substitute(R, [[38,101],[-6,-16], [31, 71], [45, 105]]), [[1, 4],[2,3],[4,9],[3,7]]); - assert_approx(back_substitute(R, [[12,48],[8,22],[11,36],[71,164]],transpose=true), [[1, 4],[2,3],[4,9],[3,7]]); - assert_approx(back_substitute([[2]], [4]), [2]); - sing1 =[[0,4,3,2], - [0,3,-4,2], - [0,0,4,5], - [0,0,0,15]]; - sing2 =[[12,4,3,2], - [0,0,-4,2], - [0,0,4,5], - [0,0,0,15]]; - sing3 = [[12,4,3,2], - [0,2,-4,2], - [0,0,4,5], - [0,0,0,0]]; - assert_approx(back_substitute(sing1, [1,2,3,4]), []); - assert_approx(back_substitute(sing2, [1,2,3,4]), []); - assert_approx(back_substitute(sing3, [1,2,3,4]), []); -} -test_back_substitute(); - - - module test_cumprod(){ @@ -829,14 +799,6 @@ test_cumprod(); -module test_outer_product(){ - assert_equal(outer_product([1,2,3],[4,5,6]), [[4,5,6],[8,10,12],[12,15,18]]); - assert_equal(outer_product([1,2],[4,5,6]), [[4,5,6],[8,10,12]]); - assert_equal(outer_product([9],[7]), [[63]]); -} -test_outer_product(); - - module test_deriv(){ pent = [for(x=[0:70:359]) [cos(x), sin(x)]]; assert_approx(deriv(pent,closed=true), diff --git a/tests/test_vectors.scad b/tests/test_vectors.scad index 0f682a9..8b287f1 100644 --- a/tests/test_vectors.scad +++ b/tests/test_vectors.scad @@ -184,7 +184,7 @@ module test_vector_search_tree(){ assert(tree2[0]==points2); ind = vector_search([5,5,1],1,tree2); assert(ind== [225, 270, 275, 276, 280, 325]); - rpts = array_group(rands(0,10,50*3,seed=seed),3); + rpts = list_to_matrix(rands(0,10,50*3,seed=seed),3); rtree = vector_search_tree(rpts); radius = 3; found0 = vector_search([0,0,0],radius,rpts); @@ -199,7 +199,7 @@ module test_vector_nearest(){ points = [for(i=[0:9], j=[0:9], k=[1:5]) [i,j,k] ]; ind1 = vector_nearest([5,5,1], 4, points); assert(ind1==[275, 225, 270, 276]); - pts = array_group(rands(0,10,50*3,seed=seed),3); + pts = list_to_matrix(rands(0,10,50*3,seed=seed),3); tree = vector_search_tree(pts); nearest = vector_nearest([0,0,0], 4, tree); closest = select(sortidx([for(p=pts) norm(p)]), [0:3]);