Sha256: 747e93a02f1bbed7e9b6f1edaf396aa96cbb5f4a14c1ba4ad372af0b898380b7

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

#
# Testing rufus-lru
#
#      Sun Oct 29 16:18:25 JST 2006
# then Tue Jan 15 12:53:04 JST 2008
#

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'test/unit'
require 'rufus/lru'


class LruTest < Test::Unit::TestCase

  #def setup
  #end
  #def teardown
  #end

  def test_0

    h = LruHash.new 3

    assert_equal 0, h.size

    h[:a] = "A"

    assert_equal 1, h.size

    h[:b] = "B"
    h[:c] = "C"

    assert_equal [ :a, :b, :c ], h.ordered_keys

    h[:d] = "D"

    assert_equal 3, h.size
    assert_equal [ :b, :c, :d ], h.ordered_keys
    assert_equal nil, h[:a]
    assert_equal "B", h[:b]
    assert_equal [ :c, :d, :b ], h.ordered_keys

    h.delete :d

    #require 'pp'
    #puts "lru keys :"
    #pp h.ordered_keys

    assert_equal 2, h.size
    assert_equal [ :c, :b ], h.ordered_keys

    h[:a] = "A"

    assert_equal 3, h.size
    assert_equal [ :c, :b, :a ], h.ordered_keys

    h[:d] = "D"


    assert_equal 3, h.size
    assert_equal [ :b, :a, :d ], h.ordered_keys

    assert_equal "B", h[:b]
    assert_equal "A", h[:a]
    assert_equal "D", h[:d]
    assert_equal nil, h[:c]
    assert_equal [ :b, :a, :d ], h.ordered_keys
  end

  def test_1

    h = LruHash.new 3

    h[1] = 10

    h.merge!({ 2 => 20, 3 => 30, 4 => 40, 5 => 50 })

    assert_nil h[1]
    assert_equal 3, h.size
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rufus-lru-1.0.3 test/test.rb