@@ -2938,39 +2938,11 @@ schwartzSort(alias transform, alias less = "a < b",
29382938 return typeof (return )(r);
29392939}
29402940
2941- @safe unittest
2942- {
2943- // issue 4909
2944- import std.typecons : Tuple ;
2945- Tuple ! (char )[] chars;
2946- schwartzSort! " a[0]" (chars);
2947- }
2948-
2949- @safe unittest
2950- {
2951- // issue 5924
2952- import std.typecons : Tuple ;
2953- Tuple ! (char )[] chars;
2954- schwartzSort! ((Tuple ! (char ) c){ return c[0 ]; })(chars);
2955- }
2956-
2941+ // /
29572942@safe unittest
29582943{
29592944 import std.algorithm.iteration : map;
2960- import std.math : log2;
2961-
2962- debug (std_algorithm) scope (success)
2963- writeln(" unittest @" , __FILE__ , " :" , __LINE__ , " done." );
2964-
2965- static double entropy (double [] probs) {
2966- double result = 0 ;
2967- foreach (ref p; probs)
2968- {
2969- if (! p) continue ;
2970- result -= p * log2(p);
2971- }
2972- return result;
2973- }
2945+ import std.numeric : entropy;
29742946
29752947 auto lowEnt = [ 1.0 , 0 , 0 ],
29762948 midEnt = [ 0.1 , 0.1 , 0.8 ],
@@ -2980,7 +2952,7 @@ schwartzSort(alias transform, alias less = "a < b",
29802952 arr[1 ] = lowEnt;
29812953 arr[2 ] = highEnt;
29822954
2983- schwartzSort! (entropy, q{ a > b} )(arr);
2955+ schwartzSort! (entropy, " a > b" )(arr);
29842956
29852957 assert (arr[0 ] == highEnt);
29862958 assert (arr[1 ] == midEnt);
@@ -2991,21 +2963,11 @@ schwartzSort(alias transform, alias less = "a < b",
29912963@safe unittest
29922964{
29932965 import std.algorithm.iteration : map;
2994- import std.math : log2 ;
2966+ import std.numeric : entropy ;
29952967
29962968 debug (std_algorithm) scope (success)
29972969 writeln(" unittest @" , __FILE__ , " :" , __LINE__ , " done." );
29982970
2999- static double entropy (double [] probs) {
3000- double result = 0 ;
3001- foreach (ref p; probs)
3002- {
3003- if (! p) continue ;
3004- result -= p * log2(p);
3005- }
3006- return result;
3007- }
3008-
30092971 auto lowEnt = [ 1.0 , 0 , 0 ],
30102972 midEnt = [ 0.1 , 0.1 , 0.8 ],
30112973 highEnt = [ 0.31 , 0.29 , 0.4 ];
@@ -3014,14 +2976,30 @@ schwartzSort(alias transform, alias less = "a < b",
30142976 arr[1 ] = lowEnt;
30152977 arr[2 ] = highEnt;
30162978
3017- schwartzSort! (entropy, q{ a < b} )(arr);
2979+ schwartzSort! (entropy, " a < b" )(arr);
30182980
30192981 assert (arr[0 ] == lowEnt);
30202982 assert (arr[1 ] == midEnt);
30212983 assert (arr[2 ] == highEnt);
30222984 assert (isSorted! (" a < b" )(map! (entropy)(arr)));
30232985}
30242986
2987+ @safe unittest
2988+ {
2989+ // issue 4909
2990+ import std.typecons : Tuple ;
2991+ Tuple ! (char )[] chars;
2992+ schwartzSort! " a[0]" (chars);
2993+ }
2994+
2995+ @safe unittest
2996+ {
2997+ // issue 5924
2998+ import std.typecons : Tuple ;
2999+ Tuple ! (char )[] chars;
3000+ schwartzSort! ((Tuple ! (char ) c){ return c[0 ]; })(chars);
3001+ }
3002+
30253003// partialSort
30263004/**
30273005Reorders the random-access range $(D r) such that the range $(D r[0
0 commit comments