mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
update
This commit is contained in:
parent
51be74b5ec
commit
d45f289a95
4 changed files with 91 additions and 10 deletions
|
@ -1244,7 +1244,7 @@ function C_div(z1,z2) =
|
|||
|
||||
// Section: Polynomials
|
||||
|
||||
// Function: polynomial()
|
||||
// Function: polynomial()
|
||||
// Usage:
|
||||
// polynomial(p, z)
|
||||
// Description:
|
||||
|
|
|
@ -787,6 +787,7 @@ function rect(size=1, center, rounding=0, chamfer=0, anchor, spin=0) =
|
|||
size = is_num(size)? [size,size] : point2d(size),
|
||||
anchor = get_anchor(anchor, center, FRONT+LEFT, FRONT+LEFT),
|
||||
complex = rounding!=0 || chamfer!=0
|
||||
, xxx = echo(anchor=anchor)echo(size=size)
|
||||
)
|
||||
(rounding==0 && chamfer==0)? let(
|
||||
path = [
|
||||
|
|
29
tests/test_all.scad
Normal file
29
tests/test_all.scad
Normal file
|
@ -0,0 +1,29 @@
|
|||
//include<hull.scad>
|
||||
include<polyhedra.scad>
|
||||
include<test_affine.scad>
|
||||
include<test_arrays.scad>
|
||||
include<test_common.scad>
|
||||
include<test_coords.scad>
|
||||
include<test_cubetruss.scad>
|
||||
include<test_debug.scad>
|
||||
include<test_edges.scad>
|
||||
include<test_errors.scad>
|
||||
include<test_geometry.scad>
|
||||
include<test_linear_bearings.scad>
|
||||
include<test_math.scad>
|
||||
include<test_mutators.scad>
|
||||
include<test_primitives.scad>
|
||||
include<test_quaternions.scad>
|
||||
include<test_queues.scad>
|
||||
include<test_shapes.scad>
|
||||
include<test_shapes2d.scad>
|
||||
include<test_skin.scad>
|
||||
include<test_stacks.scad>
|
||||
include<test_strings.scad>
|
||||
include<test_structs.scad>
|
||||
include<test_transforms.scad>
|
||||
include<test_vectors.scad>
|
||||
include<test_version.scad>
|
||||
include<test_vnf.scad>
|
||||
|
||||
|
|
@ -1,5 +1,17 @@
|
|||
include <../std.scad>
|
||||
|
||||
module test_all_numeric() {
|
||||
assert( all_numeric(1));
|
||||
assert( all_numeric([1,2,[3,4]]));
|
||||
assert( all_numeric([]));
|
||||
assert(!all_numeric([1,2,[3,"a"]]));
|
||||
assert(!all_numeric([1,2,[3,true]]));
|
||||
assert(!all_numeric([1,2,[3,NAN]]));
|
||||
assert(!all_numeric([1,2,[3,INF]]));
|
||||
assert( all_numeric([1,2,[3,[]]]));
|
||||
}
|
||||
test_all_numeric();
|
||||
|
||||
// Simple Calculations
|
||||
|
||||
module test_quant() {
|
||||
|
@ -110,6 +122,8 @@ module test_approx() {
|
|||
assert_equal(approx(1/3, 0.3333333333), true);
|
||||
assert_equal(approx(-1/3, -0.3333333333), true);
|
||||
assert_equal(approx(10*[cos(30),sin(30)], 10*[sqrt(3)/2, 1/2]), true);
|
||||
assert_equal(approx([1,[1,undef]], [1+1e-12,[1,true]]), false);
|
||||
assert_equal(approx([1,[1,undef]], [1+1e-12,[1,undef]]), true);
|
||||
}
|
||||
test_approx();
|
||||
|
||||
|
@ -342,7 +356,9 @@ module test_cumsum() {
|
|||
assert_equal(cumsum([2,2,2]), [2,4,6]);
|
||||
assert_equal(cumsum([1,2,3]), [1,3,6]);
|
||||
assert_equal(cumsum([-2,-1,0,1,2]), [-2,-3,-3,-2,0]);
|
||||
assert_equal(cumsum([-2,-1,0,1,2],3), [1,0,0,1,3]);
|
||||
assert_equal(cumsum([[1,2,3], [3,4,5], [5,6,7]]), [[1,2,3],[4,6,8],[9,12,15]]);
|
||||
assert_equal(cumsum([[1,2,3], [3,4,5], [5,6,7]], [1,0,0]), [[2,2,3],[5,6,8],[10,12,15]]);
|
||||
}
|
||||
test_cumsum();
|
||||
|
||||
|
@ -389,7 +405,6 @@ module test_mean() {
|
|||
}
|
||||
test_mean();
|
||||
|
||||
|
||||
module test_median() {
|
||||
assert_equal(median([2,3,7]), 4.5);
|
||||
assert_equal(median([[1,2,3], [3,4,5], [8,9,10]]), [4.5,5.5,6.5]);
|
||||
|
@ -397,6 +412,16 @@ module test_median() {
|
|||
test_median();
|
||||
|
||||
|
||||
module test_convolve() {
|
||||
assert_equal(convolve([],[1,2,1]), []);
|
||||
assert_equal(convolve([1,1],[]), []);
|
||||
assert_equal(convolve([1,1],[1,2,1]), [1,3,3,1]);
|
||||
assert_equal(convolve([1,2,3],[1,2,1]), [1,4,8,8,3]);
|
||||
}
|
||||
test_convolve();
|
||||
|
||||
|
||||
|
||||
module test_matrix_inverse() {
|
||||
assert_approx(matrix_inverse(rot([20,30,40])), [[0.663413948169,0.556670399226,-0.5,0],[-0.47302145844,0.829769465589,0.296198132726,0],[0.579769465589,0.0400087565481,0.813797681349,0],[0,0,0,1]]);
|
||||
}
|
||||
|
@ -583,6 +608,24 @@ module test_factorial() {
|
|||
}
|
||||
test_factorial();
|
||||
|
||||
module test_binomial() {
|
||||
assert_equal(binomial(1), [1,1]);
|
||||
assert_equal(binomial(2), [1,2,1]);
|
||||
assert_equal(binomial(3), [1,3,3,1]);
|
||||
assert_equal(binomial(5), [1,5,10,10,5,1]);
|
||||
}
|
||||
test_binomial();
|
||||
|
||||
module test_binomial_coefficient() {
|
||||
assert_equal(binomial_coefficient(2,1), 2);
|
||||
assert_equal(binomial_coefficient(3,2), 3);
|
||||
assert_equal(binomial_coefficient(4,2), 6);
|
||||
assert_equal(binomial_coefficient(10,7), 120);
|
||||
assert_equal(binomial_coefficient(10,7), binomial(10)[7]);
|
||||
assert_equal(binomial_coefficient(15,4), binomial(15)[4]);
|
||||
}
|
||||
test_binomial_coefficient();
|
||||
|
||||
|
||||
module test_gcd() {
|
||||
assert_equal(gcd(15,25), 5);
|
||||
|
@ -682,6 +725,7 @@ test_linear_solve();
|
|||
|
||||
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();
|
||||
|
@ -782,8 +826,10 @@ test_deriv3();
|
|||
|
||||
|
||||
module test_polynomial(){
|
||||
assert_equal(polynomial([],12),0);
|
||||
assert_equal(polynomial([],[12,4]),[0,0]);
|
||||
assert_equal(polynomial([0],12),0);
|
||||
assert_equal(polynomial([0],[12,4]),[0,0]);
|
||||
// assert_equal(polynomial([],12),0);
|
||||
// assert_equal(polynomial([],[12,4]),[0,0]);
|
||||
assert_equal(polynomial([1,2,3,4],3),58);
|
||||
assert_equal(polynomial([1,2,3,4],[3,-1]),[47,-41]);
|
||||
assert_equal(polynomial([0,0,2],4),2);
|
||||
|
@ -879,16 +925,20 @@ test_qr_factor();
|
|||
|
||||
module test_poly_mult(){
|
||||
assert_equal(poly_mult([3,2,1],[4,5,6,7]),[12,23,32,38,20,7]);
|
||||
assert_equal(poly_mult([3,2,1],[]),[]);
|
||||
assert_equal(poly_mult([3,2,1],[0]),[0]);
|
||||
// assert_equal(poly_mult([3,2,1],[]),[]);
|
||||
assert_equal(poly_mult([[1,2],[3,4],[5,6]]), [15,68,100,48]);
|
||||
assert_equal(poly_mult([[1,2],[],[5,6]]), []);
|
||||
assert_equal(poly_mult([[3,4,5],[0,0,0]]),[]);
|
||||
assert_equal(poly_mult([[1,2],[0],[5,6]]), [0]);
|
||||
// assert_equal(poly_mult([[1,2],[],[5,6]]), []);
|
||||
assert_equal(poly_mult([[3,4,5],[0,0,0]]),[0]);
|
||||
// assert_equal(poly_mult([[3,4,5],[0,0,0]]),[]);
|
||||
}
|
||||
test_poly_mult();
|
||||
|
||||
|
||||
|
||||
module test_poly_div(){
|
||||
assert_equal(poly_div(poly_mult([4,3,3,2],[2,1,3]), [2,1,3]),[[4,3,3,2],[]]);
|
||||
assert_equal(poly_div(poly_mult([4,3,3,2],[2,1,3]), [2,1,3]),[[4,3,3,2],[0]]);
|
||||
// assert_equal(poly_div(poly_mult([4,3,3,2],[2,1,3]), [2,1,3]),[[4,3,3,2],[]]);
|
||||
assert_equal(poly_div([1,2,3,4],[1,2,3,4,5]), [[], [1,2,3,4]]);
|
||||
assert_equal(poly_div(poly_add(poly_mult([1,2,3,4],[2,0,2]), [1,1,2]), [1,2,3,4]), [[2,0,2],[1,1,2]]);
|
||||
assert_equal(poly_div([1,2,3,4], [1,-3]), [[1,5,18],[58]]);
|
||||
|
@ -899,7 +949,8 @@ test_poly_div();
|
|||
module test_poly_add(){
|
||||
assert_equal(poly_add([2,3,4],[3,4,5,6]),[3,6,8,10]);
|
||||
assert_equal(poly_add([1,2,3,4],[-1,-2,3,4]), [6,8]);
|
||||
assert_equal(poly_add([1,2,3],-[1,2,3]),[]);
|
||||
assert_equal(poly_add([1,2,3],-[1,2,3]),[0]);
|
||||
// assert_equal(poly_add([1,2,3],-[1,2,3]),[]);
|
||||
}
|
||||
test_poly_add();
|
||||
|
||||
|
|
Loading…
Reference in a new issue