Sha256: 3841f3c4cd9e719876847fc0b0338e2b3bd63349034f96c946b6f123aa8fb70a

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

require 'spec_helper'

module Rambling
  module Trie
    describe Branches do
      describe '#add' do
        context 'new word for existing branch' do
          let(:node) { Node.new 'back' }

          before do
            node.add 'a'
          end

          it 'does not increment the child count' do
            expect(node).to have(1).children
          end

          it 'marks it as terminal' do
            expect(node[:a]).to be_terminal
          end

          it 'returns the added node' do
            expect(node.add('a').letter).to eq :a
          end
        end

        context 'old word for existing branch' do
          let(:node) { Node.new 'back' }

          before do
            node.add 'ack'
          end

          it 'does not increment any child count' do
            expect(node).to have(1).children
            expect(node[:a]).to have(1).children
            expect(node[:a][:c]).to have(1).children
            expect(node[:a][:c][:k]).to have(0).children
          end
        end
      end

      describe '#<<' do
        let(:node) { Node.new }
        let(:word) { 'word' }

        it 'delegates to #add' do
          expect((node << 'a').letter).to eq :a
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rambling-trie-0.6.1 spec/lib/rambling/trie/branches_spec.rb
rambling-trie-0.6.0 spec/lib/rambling/trie/branches_spec.rb
rambling-trie-0.5.2 spec/lib/rambling/trie/branches_spec.rb
rambling-trie-0.5.1 spec/lib/rambling/trie/branches_spec.rb
rambling-trie-0.5.0 spec/lib/rambling/trie/branches_spec.rb