Sha256: 115d937cfd14a88f7f9a6288186d183e556a58fdd2992c32aaf93106a0b28754

Contents?: true

Size: 1 KB

Versions: 8

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

shared_examples_for 'a compressible trie' do
  context 'and the trie is not compressed' do
    it_behaves_like 'a trie data structure'

    it 'does not alter the input' do
      word = 'string'
      add_word trie, word

      expect(word).to eq 'string'
    end

    it 'is marked as not compressed' do
      expect(trie).not_to be_compressed
    end
  end

  context 'and the trie is compressed' do
    let!(:original_root) { trie.root }
    let!(:original_keys) { original_root.children_tree.keys }
    let!(:original_values) { original_root.children_tree.values }

    before do
      trie.compress!
    end

    it_behaves_like 'a trie data structure'

    it 'is marked as compressed' do
      expect(trie).to be_compressed
    end

    it 'leaves the original root intact' do
      expect(original_root.children_tree.keys).to eq original_keys
      expect(trie.children_tree.keys).to eq original_keys
      expect(trie.children_tree.values).not_to eq original_values
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
rambling-trie-2.3.0 spec/support/shared_examples/a_compressible_trie.rb
rambling-trie-2.2.1 spec/support/shared_examples/a_compressible_trie.rb
rambling-trie-2.2.0 spec/support/shared_examples/a_compressible_trie.rb
rambling-trie-opal-2.1.1.1 spec/support/shared_examples/a_compressible_trie.rb
rambling-trie-opal-2.1.1 spec/support/shared_examples/a_compressible_trie.rb
rambling-trie-2.1.1 spec/support/shared_examples/a_compressible_trie.rb
rambling-trie-2.1.0 spec/support/shared_examples/a_compressible_trie.rb
rambling-trie-2.0.0 spec/support/shared_examples/a_compressible_trie.rb