1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-02-11 11:00:53 +01:00
dotSCAD/test/util/test_sort.scad

28 lines
832 B
OpenSCAD
Raw Normal View History

2020-01-26 16:54:09 +08:00
use <util/sort.scad>;
2020-01-26 16:26:19 +08:00
2019-06-27 08:53:15 +08:00
module test_sort() {
echo("==== test_sort ====");
2021-02-07 12:13:32 +08:00
assert(
[[2, 0, 0], [5, 0, 0], [7, 0, 0], [9, 0, 0], [10, 0, 0]] ==
sort([[10, 0, 0], [5, 0, 0], [7, 0, 0], [2, 0, 0], [9, 0, 0]])
2019-06-27 08:53:15 +08:00
);
2021-02-07 12:13:32 +08:00
assert(
[[2, 0, 0], [5, 0, 0], [7, 0, 0], [9, 0, 0], [10, 0, 0]] ==
sort([[10, 0, 0], [5, 0, 0], [7, 0, 0], [2, 0, 0], [9, 0, 0]], by = "x")
2019-06-27 08:53:15 +08:00
);
2021-02-07 12:13:32 +08:00
assert(
[[0, 2, 0], [0, 5, 0], [0, 7, 0], [0, 9, 0], [0, 10, 0]] ==
sort([[0, 10, 0], [0, 5, 0], [0, 7, 0], [0, 2, 0], [0, 9, 0]], by = "idx", idx = 1)
2019-06-27 08:53:15 +08:00
);
2021-02-07 12:13:32 +08:00
ascending = function(e1, e2) e1 - e2;
descending = function(e1, e2) e2 - e1;
assert(sort([2, 1, 3, 5, 4], by = ascending) == [1, 2, 3, 4, 5]);
assert(sort([2, 1, 3, 5, 4], by = descending) == [5, 4, 3, 2, 1]);
2019-06-27 08:53:15 +08:00
}
test_sort();