From 86fc7dc1439752962d3467e0f7372141affd017d Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Wed, 30 Jun 2021 19:56:17 -0700 Subject: [PATCH 1/2] Improved regressions error reporting. --- common.scad | 1 + strings.scad | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/common.scad b/common.scad index 9ffade5..c172cbb 100644 --- a/common.scad +++ b/common.scad @@ -577,6 +577,7 @@ module no_module() { function _valstr(x) = + is_string(x)? str("\"",str_replace_char(x, "\"", "\\\""),"\"") : is_list(x)? str("[",str_join([for (xx=x) _valstr(xx)],","),"]") : is_num(x) && x==floor(x)? fmt_int(x) : is_finite(x)? fmt_float(x,12) : x; diff --git a/strings.scad b/strings.scad index 1577aee..732595f 100644 --- a/strings.scad +++ b/strings.scad @@ -734,7 +734,7 @@ function str_pad(str,length,char=" ",left=false) = // can be any string. function str_replace_char(str,char,replace) = assert(is_str(str)) - assert(is_str(char) && len(char)==1, "Search pattern 'char' must be a a single character string") + assert(is_str(char) && len(char)==1, "Search pattern 'char' must be a single character string") assert(is_str(replace)) str_join([for(c=str) c==char ? replace : c]); From 23f4de897a2afb7b826af3e65eb24ec1df801200 Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Wed, 30 Jun 2021 19:57:03 -0700 Subject: [PATCH 2/2] Added regressions for group_data() and all_integer() --- tests/test_arrays.scad | 9 +++++++++ tests/test_math.scad | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/tests/test_arrays.scad b/tests/test_arrays.scad index a66aeed..3aec4b7 100644 --- a/tests/test_arrays.scad +++ b/tests/test_arrays.scad @@ -589,6 +589,15 @@ module test_array_group() { test_array_group(); +module test_group_data() { + assert_equal(group_data([1,2,0], ["A","B","C"]), [["C"],["A"],["B"]]); + assert_equal(group_data([1,3,0], ["A","B","C"]), [["C"],["A"],[],["B"]]); + assert_equal(group_data([5,3,1], ["A","B","C"]), [[],["C"],[],["B"],[],["A"]]); + assert_equal(group_data([1,3,1], ["A","B","C"]), [[],["A","C"],[],["B"]]); +} +test_group_data(); + + module test_flatten() { assert(flatten([[1,2,3], [4,5,[6,7,8]]]) == [1,2,3,4,5,[6,7,8]]); assert(flatten([]) == []); diff --git a/tests/test_math.scad b/tests/test_math.scad index b5c25b8..ad50ebb 100644 --- a/tests/test_math.scad +++ b/tests/test_math.scad @@ -227,6 +227,26 @@ module test_all_nonnegative() { test_all_nonnegative(); +module test_all_integer() { + assert(!all_integer(undef)); + assert(!all_integer(true)); + assert(!all_integer(false)); + assert(!all_integer(4.3)); + assert(!all_integer("foo")); + assert(!all_integer([])); + assert(!all_integer([3,4.1,5,7])); + assert(!all_integer([[1,2,3],[4,5,6],[7,8]])); + assert(all_integer(-4)); + assert(all_integer(0)); + assert(all_integer(5)); + assert(all_integer([-3])); + assert(all_integer([0])); + assert(all_integer([3])); + assert(all_integer([2,-4,0,5,7,9876543210])); +} +test_all_integer(); + + module test_approx() { assert_equal(approx(PI, 3.141592653589793236), true); assert_equal(approx(PI, 3.1415926), false);