Sha256: 6a4de53fdb896f96a4bfd04db76d155ac3e63cdd8786b52b258481a4f4e1d87e
Contents?: true
Size: 1.43 KB
Versions: 4
Compression:
Stored size: 1.43 KB
Contents
require_relative "spec_helper" require 'tempfile' describe Melisa::Trie do let(:terms) { ['one', 'two', 'onetwo'] } let(:trie) { Melisa::Trie.new(terms) } it "initializes" do trie end it "tests for inclusion" do expect(trie).to include 'one' expect(trie).to_not include 'three' end it "lists keys" do expect(trie.keys).to match_array ['one', 'two', 'onetwo'] end it "saves" do tmp = Tempfile.new('melisa') trie.save(tmp.path) trie2 = Melisa::Trie.new trie2.load(tmp.path) expect(trie2.keys).to match_array ['one', 'two', 'onetwo'] end it "gets a key's integer ID" do expect(trie.get_id('NOT_KEY1')).to be_nil expect(trie.get_id('NOT_KEY2')).to be_nil expect(trie.get_id('one')).to eq 0 expect(trie.get_id('two')).to eq 1 expect(trie.get_id('onetwo')).to eq 2 end it "gets a key given an ID" do expect(trie.get_key(0)).to eq 'one' expect(trie.get_key(1)).to eq 'two' expect(trie.get_key(2)).to eq 'onetwo' expect{ trie.get_key(3) }.to raise_error end it "returns size before being built" do expect(trie.size).to eq 3 expect(trie.built?).to be_falsy end it "returns size after built built" do trie.build expect(trie.built?).to be_truthy expect(trie.size).to eq 3 end it "#each iterates alphabetically and yields keys" do expect { |b| trie.each(&b) }.to \ yield_successive_args('one', 'onetwo', 'two') end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
melisa-0.2.5 | spec/trie_spec.rb |
melisa-0.2.4 | spec/trie_spec.rb |
melisa-0.2.3 | spec/trie_spec.rb |
melisa-0.2.2 | spec/trie_spec.rb |