Bug 12589 – std.random.randomCover fails for empty ranges

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-04-16T15:15:00Z
Last change time
2015-02-18T03:40:34Z
Assigned to
nobody
Creator
jens.k.mueller

Comments

Comment #0 by jens.k.mueller — 2014-04-16T15:15:03Z
The following code fails (the second assert does not hold). unittest { import std.random; int[] r = []; auto gen = Random(0); auto c = randomCover(r, gen); assert(c.length == 0); assert(c.empty); } Since empty is false calling front is valid which leads to disaster. I used DMD64 D Compiler v2.065 on Linux.
Comment #1 by github-bugzilla — 2014-12-06T18:42:58Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/2e5bb505318ba20847472927739b41562d6d6c48 Fix issue 12589 - std.random.randomCover fails for empty ranges https://github.com/D-Programming-Language/phobos/commit/3489c3d5baba90334b1bcb452ad32d61496f5e55 Merge pull request #2787 from sinkuu/randomcover Fix issue 12589 - std.random.randomCover fails for empty ranges
Comment #2 by github-bugzilla — 2015-02-18T03:40:34Z