From ed0a3e3e7b524d1706b0c2c4a52c587c0f040193 Mon Sep 17 00:00:00 2001 From: Garth Minette <gminette@gmail.com> Date: Fri, 3 Jul 2020 15:23:03 -0700 Subject: [PATCH] Added regressions for set functions and force_list() --- tests/test_arrays.scad | 58 +++++++++++++++++++++++++++++++++++++++++- version.scad | 2 +- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/tests/test_arrays.scad b/tests/test_arrays.scad index 71fa750..0ed2bd6 100644 --- a/tests/test_arrays.scad +++ b/tests/test_arrays.scad @@ -252,7 +252,6 @@ module test_sortidx() { } test_sortidx(); - module test_unique() { assert(unique([]) == []); assert(unique([8]) == [8]); @@ -261,6 +260,54 @@ module test_unique() { test_unique(); +module test_unique_count() { + assert_equal( + unique_count([3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,6]), + [[1,2,3,4,5,6,7,8,9],[2,2,4,1,3,2,1,1,3]] + ); + assert_equal( + unique_count(["A","B","R","A","C","A","D","A","B","R","A"]), + [["A","B","C","D","R"],[5,2,1,1,2]] + ); +} +test_unique_count(); + + + +// Sets + +module test_set_union() { + assert_equal( + set_union([2,3,5,7,11], [1,2,3,5,8]), + [2,3,5,7,11,1,8] + ); + assert_equal( + set_union([2,3,5,7,11], [1,2,3,5,8], get_indices=true), + [[5,0,1,2,6],[2,3,5,7,11,1,8]] + ); +} +test_set_union(); + + +module test_set_difference() { + assert_equal( + set_difference([2,3,5,7,11], [1,2,3,5,8]), + [7,11] + ); +} +test_set_difference(); + + +module test_set_intersection() { + assert_equal( + set_intersection([2,3,5,7,11], [1,2,3,5,8]), + [2,3,5] + ); +} +test_set_intersection(); + + + // Arrays @@ -273,6 +320,15 @@ module test_subindex() { test_subindex(); +module test_force_list() { + assert_equal(force_list([3,4,5]), [3,4,5]); + assert_equal(force_list(5), [5]); + assert_equal(force_list(7, n=3), [7,7,7]); + assert_equal(force_list(4, n=3, fill=1), [4,1,1]); +} +test_force_list(); + + module test_pair() { assert(pair([3,4,5,6]) == [[3,4], [4,5], [5,6]]); assert(pair("ABCD") == [["A","B"], ["B","C"], ["C","D"]]); diff --git a/version.scad b/version.scad index 71f7df3..78d41d3 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,375]; +BOSL_VERSION = [2,0,376]; // Section: BOSL Library Version Functions