Sha256: 0b74929432c89f0d1fa50a79177c3e0137b15c8ae955afff9427a68fa2803d5c

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

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

          before :each do
            node.add_branch_from 'a'
          end

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

          it 'marks it as terminal' do
            node[:a].should be_terminal
          end
        end

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

          before :each do
            node.add_branch_from 'ack'
          end

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

      describe '#<<' do
        let(:root) { Root.new }
        let(:word) { 'word' }

        it 'delegates to #add_branch_from' do
          [true, false].each do |value|
            root.stub(:add_branch_from).with(word).and_return value
            root << word
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rambling-trie-0.4.2 spec/lib/rambling/trie/branches_spec.rb
rambling-trie-0.4.1 spec/lib/rambling-trie/branches_spec.rb