For the semi-automatic test for
SpreadSheetPlugin, the tests are shipped as an extra topic
SpreadSheetPluginTestCases. Every now and then the test for
$HASHREVERSE
fails like this:
Expected HASHREVERSE |
---|
<ul> <li> $SETHASH()=|| </li> <li> $LIST2HASH(age, Jane, 26, Tim, 27, Sam, 27)=|| </li> <li> $HASHREVERSE(age)=|| </li> <li> |
$HASH2LIST(age, $key: $value)=|26: Jane, 27: Tim| |
$HASH2LIST(age, $key: $value)=|26: Jane, 27: Sam| |
</li> <li> $HASHREVERSE(height)=|| </li> <li> $HASH2LIST(height)=|| </li> <li> $HASHREVERSE()=|| </li> </ul> |
Root cause: Since Perl 5.18, Perl randomizes the order of keys in a hash. The two hash entries for
Tim
and
Sam
both share a value of 27. On flipping the hash over, it has always been known and expected behavior that only one of the two can survive under the key of 27 in the reversed hash. But as of today, we can't know which one.
Fix: Pretend that Sam had his birthday yesterday and make him 28 years old. This should to be changed in the plugin docs, too, though the warning " Hash keys are always unique, e.g. multiple identical values will be reduced to one key." should be kept in place.
Side note: The function
$HASH2LIST
sorts the keys of the hash before converting to a list and is therefore
not affected by the randomization.
--
TWiki:Main/HaraldJoerg
- 2017-10-20