Bug 7287 – std.container.BinaryHeap example fails

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2012-01-12T21:52:00Z
Last change time
2014-02-12T23:31:29Z
Assigned to
nobody
Creator
nilsbossung

Comments

Comment #0 by nilsbossung — 2012-01-12T21:52:21Z
The example from http://www.dlang.org/phobos/std_container#BinaryHeap fails: --- import std.algorithm, std.container; void main() { // Example from "Introduction to Algorithms" Cormen et al, p 146 int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ]; auto h = heapify(a); // largest element assert(h.front == 16); // a has the heap property assert(equal(a, [ 16, 14, 10, 9, 8, 7, 4, 3, 2, 1 ])); } --- core.exception.AssertError@test(9): Assertion failure Tested with dmd 2.057 and 2.058head. Interestingly, the corresponding unit test in container.d differs slightly from the example (and passes).
Comment #1 by lovelydear — 2012-04-19T14:11:13Z
Fails also on Win32 2.059
Comment #2 by alienballance — 2012-11-28T16:42:50Z
same on dmd 2.060 (linux x64) http://dpaste.dzfl.pl/1bd35a26
Comment #3 by github-bugzilla — 2014-02-12T22:52:24Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/80ef8ef7f5f85ed8e7bf5b4d51eea9bc99f0f6d6 Fix Issue 7287 - BinaryHeap example Two changes: 1. Fixed the array in the final assert. Not sure where the original array came from -- not Intro to Algorithms, I checked my copy! 2. Moved to documented unit test so we make sure it actually passes. https://d.puremagic.com/issues/show_bug.cgi?id=7287 https://github.com/D-Programming-Language/phobos/commit/a60b269425a3133d5c26794067c03c329255742c Merge pull request #1931 from Poita/bug7287 Fix Issue 7287 - BinaryHeap example