mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-01-16 13:50:23 +01:00
adjust tests
This commit is contained in:
parent
2eff8ec203
commit
817165a833
@ -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]]);
|
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;
|
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]];
|
data3 = [for (d=data2) [d.x,d.y,d.x*3+d.y*5+2]];
|
||||||
planept = select(data3,0,N-4);
|
planept = select(data3,0,N-4);
|
||||||
testpt = select(data3, N-3,-1);
|
testpt = select(data3, N-3,-1);
|
||||||
|
@ -154,6 +154,49 @@ module test_null_space(){
|
|||||||
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() {
|
module test_column() {
|
||||||
v = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]];
|
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]);
|
assert(column(v,2) == [3, 7, 11, 15]);
|
||||||
|
@ -775,36 +775,6 @@ module test_c_norm(){
|
|||||||
}
|
}
|
||||||
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(){
|
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(){
|
module test_deriv(){
|
||||||
pent = [for(x=[0:70:359]) [cos(x), sin(x)]];
|
pent = [for(x=[0:70:359]) [cos(x), sin(x)]];
|
||||||
assert_approx(deriv(pent,closed=true),
|
assert_approx(deriv(pent,closed=true),
|
||||||
|
@ -184,7 +184,7 @@ module test_vector_search_tree(){
|
|||||||
assert(tree2[0]==points2);
|
assert(tree2[0]==points2);
|
||||||
ind = vector_search([5,5,1],1,tree2);
|
ind = vector_search([5,5,1],1,tree2);
|
||||||
assert(ind== [225, 270, 275, 276, 280, 325]);
|
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);
|
rtree = vector_search_tree(rpts);
|
||||||
radius = 3;
|
radius = 3;
|
||||||
found0 = vector_search([0,0,0],radius,rpts);
|
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] ];
|
points = [for(i=[0:9], j=[0:9], k=[1:5]) [i,j,k] ];
|
||||||
ind1 = vector_nearest([5,5,1], 4, points);
|
ind1 = vector_nearest([5,5,1], 4, points);
|
||||||
assert(ind1==[275, 225, 270, 276]);
|
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);
|
tree = vector_search_tree(pts);
|
||||||
nearest = vector_nearest([0,0,0], 4, tree);
|
nearest = vector_nearest([0,0,0], 4, tree);
|
||||||
closest = select(sortidx([for(p=pts) norm(p)]), [0:3]);
|
closest = select(sortidx([for(p=pts) norm(p)]), [0:3]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user