Talk:Sorting algorithms/Strand sort: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 3: Line 3:
: The linearRemove does sometimes not remove the first item, although "find" and "take" return the correct result. I've posted a workaround but I haven't been able to trace the actual problem. [[User:Fwend|Fwend]] 16:18, 3 August 2012 (UTC)
: The linearRemove does sometimes not remove the first item, although "find" and "take" return the correct result. I've posted a workaround but I haven't been able to trace the actual problem. [[User:Fwend|Fwend]] 16:18, 3 August 2012 (UTC)
:: Good. I suggest a fuzzy testing to see if your code is correct (this means generating many different random inputs and verifying the output is fully correct). And it's not hard to find bugs in Phobos. Finding and fixing bugs in DMD/Phobos is important. So if you find that the cause is in Phobos, you will avoid some troubles to future D users.[[User:Bearophile|bearophile]]
:: Good. I suggest a fuzzy testing to see if your code is correct (this means generating many different random inputs and verifying the output is fully correct). And it's not hard to find bugs in Phobos. Finding and fixing bugs in DMD/Phobos is important. So if you find that the cause is in Phobos, you will avoid some troubles to future D users.[[User:Bearophile|bearophile]]
::: Not good, try DList!int([-5, -5, 8]) The simple fuzzy testing code I've used: <lang d>void main() {
import std.random, std.conv;

foreach (_; 0 .. 1000) {
auto data = new int[uniform(0, 5)];
foreach (ref x; data)
x = uniform(-5, 10);
auto lst = DList!int(data);
int[] result = strandSort(lst).array();
int[] sortedData = data.dup.sort().release();
assert(result == sortedData, text("\n", data, "\n", result, "\n", sortedData));
}
}</lang>

Revision as of 16:46, 3 August 2012

D Entry

The D entry code (that maybe was written by Fwend) contains one or more bugs, it prints "-1 -1" even if the input contains only one -1.

The linearRemove does sometimes not remove the first item, although "find" and "take" return the correct result. I've posted a workaround but I haven't been able to trace the actual problem. Fwend 16:18, 3 August 2012 (UTC)
Good. I suggest a fuzzy testing to see if your code is correct (this means generating many different random inputs and verifying the output is fully correct). And it's not hard to find bugs in Phobos. Finding and fixing bugs in DMD/Phobos is important. So if you find that the cause is in Phobos, you will avoid some troubles to future D users.bearophile
Not good, try DList!int([-5, -5, 8]) The simple fuzzy testing code I've used: <lang d>void main() {
   import std.random, std.conv;
   foreach (_; 0 .. 1000) {
       auto data = new int[uniform(0, 5)];
       foreach (ref x; data)
           x = uniform(-5, 10);
       auto lst = DList!int(data);
       int[] result = strandSort(lst).array();
       int[] sortedData = data.dup.sort().release();
       assert(result == sortedData, text("\n", data, "\n", result, "\n", sortedData));
   }

}</lang>