Skip Menu |

This queue is for tickets about the List-Priority CPAN distribution.

Report information
The Basics
Id: 69410
Status: resolved
Priority: 0/
Queue: List-Priority

People
Owner: Nobody in particular
Requestors: CALDRIN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.02
Fixed in: (no value)



Subject: Shift returns most important element
According to documentation shift() is supposed to return the least important element. In fact it returns the most important element. I wrote a small set of unit tests to demonstrate the issue. Furthermore, I wrote a patch to fix the issue.
Subject: 0001--TEST-added-unit-tests.patch
From e44bdd619774866ef1256c3b8e4467a4553976c6 Mon Sep 17 00:00:00 2001 From: Maik Hentsche <maik@mm-double.de> Date: Mon, 11 Jul 2011 21:07:37 +0200 Subject: [PATCH] [TEST] added unit tests --- t/00-load.t | 10 ++++++++++ t/02-small-list.t | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) create mode 100644 t/00-load.t create mode 100644 t/02-small-list.t diff --git a/t/00-load.t b/t/00-load.t new file mode 100644 index 0000000..7da4c20 --- /dev/null +++ b/t/00-load.t @@ -0,0 +1,10 @@ +use Test::More; + +BEGIN{ + use_ok('List::Priority'); +} + +my $list = List::Priority->new(); +isa_ok($list, 'List::Priority'); + +done_testing; diff --git a/t/02-small-list.t b/t/02-small-list.t new file mode 100644 index 0000000..b0b7480 --- /dev/null +++ b/t/02-small-list.t @@ -0,0 +1,26 @@ +use Test::More; + +BEGIN{ + use_ok('List::Priority'); +} + +my $list = List::Priority->new(); + +$list->insert(2,'World!'); +$list->insert(5,'Hello'); +$list->insert(3,' '); + +is($list->pop(), 'Hello', 'Most important element'); + +my $error = $list->insert(2,'World!'); +is($error, 'List::Priority - Object already on the list', 'Duplicate element'); + +for my $count (6..12) { + $list->insert($count, "element$count"); + $list->insert($count, "second$count"); +} + +is($list->pop(7), 'element7', 'First element with prio 7'); +is($list->shift(), 'World!', 'Least important element'); + +done_testing; -- 1.6.0.4
Am Mo 11. Jul 2011, 15:16:52, CALDRIN schrieb: Show quoted text
> I wrote a small set of unit tests to demonstrate the issue. > Furthermore, I wrote a patch to fix the issue.
Find the fix attached.
Subject: 0001--FIX-shift-delivers-lowest-prio-element-now.patch
From 18feb53845ca913c7aeca6235b8e1da39fcffa83 Mon Sep 17 00:00:00 2001 From: Maik Hentsche <maik@mm-double.de> Date: Mon, 11 Jul 2011 21:12:50 +0200 Subject: [PATCH] [FIX] shift delivers lowest prio element now --- Priority.pm | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Priority.pm b/Priority.pm index dbf905f..4913f9f 100644 --- a/Priority.pm +++ b/Priority.pm @@ -111,7 +111,7 @@ sub shift { } else { # Find out the bottom priority - ($bottom_priority) = (sort {$b <=> $a} keys %{$self->{queues}}); + ($bottom_priority) = (sort {$a <=> $b} keys %{$self->{queues}}); return undef unless (defined ($bottom_priority)); } -- 1.6.0.4
On Mon Jul 11 15:17:38 2011, CALDRIN wrote: Show quoted text
> Am Mo 11. Jul 2011, 15:16:52, CALDRIN schrieb:
> > I wrote a small set of unit tests to demonstrate the issue. > > Furthermore, I wrote a patch to fix the issue.
> > Find the fix attached.
Great, thanks very much! I've taken over maintainership and applied your patch in v0.03rc1, which should now be visible.