From 5f7a4ca7c541957eca462cc880859a1ed15cc46b Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Mon, 16 May 2016 01:40:45 +0300 Subject: [PATCH] add top-level example for binary heap --- std/container/binaryheap.d | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/std/container/binaryheap.d b/std/container/binaryheap.d index 901d111dc9d..2d1e00e5b66 100644 --- a/std/container/binaryheap.d +++ b/std/container/binaryheap.d @@ -25,6 +25,18 @@ import std.traits; public import std.container.util; +/// +unittest +{ + import std.algorithm.comparison : equal; + import std.range : take; + auto maxHeap = heapify([4, 7, 3, 1, 5]); + assert(maxHeap.take(3).equal([7, 5, 4])); + + auto minHeap = heapify!"a > b"([4, 7, 3, 1, 5]); + assert(minHeap.take(3).equal([1, 3, 4])); +} + // BinaryHeap /** Implements a $(WEB en.wikipedia.org/wiki/Binary_heap, binary heap)