Fix rollover bug in nextEvenPermutation.

This commit is contained in:
H. S. Teoh 2013-01-01 09:28:14 -08:00
parent d13845de2c
commit 09674dd4ca

View file

@ -10854,8 +10854,6 @@ bool nextEvenPermutation(alias less="a<b", BidirectionalRange)
swap(i.front, j.front);
oddParity = !oddParity;
ret = true;
}
else
{
@ -10903,3 +10901,15 @@ unittest
assert(nextEvenPermutation!"a > b"(a) == false);
assert(a == [ 3, 2, 1 ]);
}
unittest
{
// Test various cases of rollover
auto a = [ 3, 1, 2 ];
assert(nextEvenPermutation(a) == false);
assert(a == [ 1, 2, 3 ]);
auto b = [ 3, 2, 1 ];
assert(nextEvenPermutation(b) == false);
assert(b == [ 1, 3, 2 ]);
}