mirror of
https://github.com/dlang/phobos.git
synced 2025-05-14 08:55:54 +03:00
Fix rollover bug in nextEvenPermutation.
This commit is contained in:
parent
d13845de2c
commit
09674dd4ca
1 changed files with 12 additions and 2 deletions
|
@ -10854,8 +10854,6 @@ bool nextEvenPermutation(alias less="a<b", BidirectionalRange)
|
||||||
|
|
||||||
swap(i.front, j.front);
|
swap(i.front, j.front);
|
||||||
oddParity = !oddParity;
|
oddParity = !oddParity;
|
||||||
|
|
||||||
ret = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -10903,3 +10901,15 @@ unittest
|
||||||
assert(nextEvenPermutation!"a > b"(a) == false);
|
assert(nextEvenPermutation!"a > b"(a) == false);
|
||||||
assert(a == [ 3, 2, 1 ]);
|
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 ]);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue