/ test / util / test_sort.scad
test_sort.scad
 1  use <util/sort.scad>
 2  
 3  module test_sort() {
 4      echo("==== test_sort ====");
 5  
 6      assert(
 7          [[2, 0, 0], [5, 0, 0], [7, 0, 0], [9, 0, 0], [10, 0, 0]] == 
 8          sort([[10, 0, 0], [5, 0, 0], [7, 0, 0], [2, 0, 0], [9, 0, 0]])
 9      );
10  
11      assert(
12          [[2, 0, 0], [5, 0, 0], [7, 0, 0], [9, 0, 0], [10, 0, 0]] == 
13          sort([[10, 0, 0], [5, 0, 0], [7, 0, 0], [2, 0, 0], [9, 0, 0]], by = "x")
14      );
15  
16      assert(
17          [[0, 2, 0], [0, 5, 0], [0, 7, 0], [0, 9, 0], [0, 10, 0]] == 
18          sort([[0, 10, 0], [0, 5, 0], [0, 7, 0], [0, 2, 0], [0, 9, 0]], by = "idx", idx = 1)
19      );
20  
21      assert(
22          [[9, 0, 2], [2, 0, 3], [7, 0, 4], [5, 0, 5], [10, 0, 6]] == 
23          sort([[10, 0, 6], [5, 0, 5], [7, 0, 4], [2, 0, 3], [9, 0, 2]], by = "vt")
24      );    
25   
26      ascending = function(e1, e2) e1 - e2;
27      descending = function(e1, e2) e2 - e1;
28      assert(sort([2, 1, 3, 5, 4], by = ascending) == [1, 2, 3, 4, 5]);
29      assert(sort([2, 1, 3, 5, 4], by = descending) == [5, 4, 3, 2, 1]);
30  }
31  
32  test_sort();