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