On 19/10/05, ES <ruby-ml / magical-cat.org> wrote:
> Brian Schröäer wrote:
> > > [snip]
> >
> > "delete_min_return_priority" returns the priority of the element that
> > was removed by calling this method.
>
> I am still not sure :) By 'this method', do you mean delete/dequeue?
> Or does delete_min_return_priority itself delete?
>
> If it does not delete, then #last_(deleted_)priority is fine; otherwise
> you might do something like #dequeue_by and document the return value.
> It would get excessively verbose to include all that information in the
> method name.
>

delete_min_return_priority deletes the key that has the lowest
assigned priority and returns this priority. delete_min_return_key
does the same but returns the key that had the lowest assigned
priority. Finally delete_min deletes the same key and returns a pair
[key, priority].

Maybe the testcases will make it all clear. If I'm not able to express
myself in english, maybe my ruby is more adequate. All the three tests
should do the same. Only the return value should differ.

  def test_delete_min
    assert_equal(nil, @q.delete_min, "Empty queue should pop nil")
    @q["n1"] = 0
    assert_equal(["n1", 0], @q.delete_min)
    @q["n1"] = 0
    @q["n2"] = -1
    assert_equal(["n2", -1], @q.delete_min)
  end

  def test_delete_min_return_key
    assert_equal(nil, @q.delete_min_return_key, "Empty queue should pop nil")
    @q["n1"] = 0
    assert_equal("n1", @q.delete_min_return_key)
    @q["n1"] = 0
    @q["n2"] = -1
    assert_equal("n2", @q.delete_min_return_key)
  end

  def test_delete_min_return_priority
    assert_equal(nil, @q.delete_min_return_priority, "Empty queue
should pop nil")
    @q["n1"] = 0
    assert_equal(0, @q.delete_min_return_priority)
    @q["n1"] = 0
    @q["n2"] = -1
    assert_equal(-1, @q.delete_min_return_priority)
  end

best regards,

Brian

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/