http://qs321.pair.com?node_id=1056385


in reply to Truly randomized keys() in perl 5.17 - a challenge for testing?

Let me clarify: The module referenced in the original posting has a function hash_serialize() that takes a reference to a hash like { a => "b", c => "d" } and turns it into something like "a=b&c=d" or "c=d&a=b", depending on what keys() returns underneath:

https://github.com/mschilli/php-httpbuildquery-perl/blob/master/HTTPBuildQuery.pm#L63

Now how am I supposed to test that the outcome is what I'd expect? With two hash elements, you could argue that I could generate all permutations of possible result strings and check if one of them matches the one I got by running the function, but with thousand entries this becomes unwieldy.

The general problem is this: I have an unpredictable function (keys()) and its result gets processed, and the processed result needs to get checked against an expected outcome.

Unless keys() can be switched to a test mode to produce predictable results (doesn't need to be sorted, just give me something predictable, like before perl 5.17), what are the options?

By the way, some people have suggested to use "sort keys" in my algorithm every time, but putting in extra complexity (sort) at runtime to make sure I can test perfectly fine code is just plain wrong.