assoc-heaps: adding / fixing test case.

windows-high-dpi
John Benediktsson 2018-02-14 16:52:53 -08:00
parent c0a8d0cf1f
commit 3a1fb4d588
3 changed files with 11 additions and 8 deletions

View File

@ -21,11 +21,6 @@ TUPLE: heap { data vector } ;
: <heap> ( class -- heap )
V{ } clone swap boa ; inline
ERROR: not-a-heap object ;
: check-heap ( heap -- heap )
dup heap? [ not-a-heap ] unless ; inline
TUPLE: entry value key heap index ;
: <entry> ( value key heap -- entry )
@ -148,7 +143,6 @@ M: heap heap-pop
[ data-first >entry< ] [ heap-pop* ] bi ;
: slurp-heap ( ... heap quot: ( ... value key -- ... ) -- ... )
[ check-heap ] dip
[ drop '[ _ heap-empty? ] ]
[ '[ _ heap-pop @ ] until ] 2bi ; inline

View File

@ -1,4 +1,11 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test assoc-heaps ;
IN: assoc-heaps.tests
USING: assoc-heaps combinators heaps kernel tools.test ;
{ { { 0 "zero" } { 1 "one" } { 2 "two" } } } [
<unique-min-heap>
"two" 2 pick heap-push
"zero" 0 pick heap-push
"one" 1 pick heap-push
heap-pop-all
] unit-test

View File

@ -25,3 +25,5 @@ M: assoc-heap heap-pop heap>> heap-pop ;
M: assoc-heap heap-peek heap>> heap-peek ;
M: assoc-heap heap-empty? heap>> heap-empty? ;
M: assoc-heap heap-size heap>> heap-size ;