Created
June 21, 2009 14:12
-
-
Save moro/133519 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
$: << File.expand_path('../lib', File.dirname(__FILE__)) | |
require 'lru_hash' | |
describe LRUHash do | |
describe "ハッシュのように使えて、キー:fooに'hoge'を追加した場合" do | |
before do | |
@hash = LRUHash.new | |
@hash[:foo] = "hoge" | |
end | |
subject{ @hash[:foo] } | |
it "[]で読み出せること" do | |
should == "hoge" | |
end | |
it "サイズは1であること" do | |
@hash.size.should == 1 | |
end | |
it "include ':foo'がtrueであること" do | |
@hash.should include :foo | |
end | |
end | |
describe "最大サイズを100に指定する場合" do | |
before do | |
@hash = LRUHash.new(100) | |
end | |
it "最大サイズは100であること" do | |
@hash.max_size.should == 100 | |
end | |
describe "101種の値を設定した場合" do | |
before do | |
101.times{|i| @hash[i] = i.to_s } | |
end | |
it "サイズは100であること" do | |
@hash.size.should == 100 | |
end | |
it "0(もっとも古いもの)が消えていること" do | |
@hash.should_not have_key(0) | |
end | |
describe "1を読み出して、もう一つ入れた場合" do | |
before do | |
@hash[1] | |
@hash[102] = '102' | |
end | |
it "hash[1]が残っていること" do | |
@hash.should have_key(1) | |
end | |
it "hash[2]が消えていること" do | |
@hash.should_not have_key(2) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment