1() = evalfile ("./common.sl"); 2 3require ("rand"); 4require ("listfuns"); 5 6define test_heap (n, dir) 7{ 8 variable rnums = rand_uniform (n); 9 10 variable i; 11 variable list = {}; 12 _for i (0, n/2-1, 1) 13 list_append (list, rnums[i]); 14 15 variable h = heap_new (list; dir=dir); 16 17 _for i (n/2, n-1, 1) 18 h.add (rnums[i]); 19 20 list = {}; 21 while (h.length ()) 22 { 23 list_append (list, h.remove()); 24 } 25 rearrange (rnums, array_sort (rnums; dir=dir)); 26 27 if (length (rnums) != length (list)) 28 failed ("length of list != length of array"); 29 30 if (length (rnums) && any (rnums != list_to_array (list))) 31 failed ("heap sorted list does not match sorted array"); 32} 33 34define slsh_main () 35{ 36 start_test ("listfuns"); 37 srand (0); 38 variable i; 39 _for i (0, 33, 1) 40 { 41 test_heap (i, 1); 42 test_heap (i, -1); 43 } 44 end_test(); 45} 46