Sha256: 24537a06b78f78b88d068eca42f99296bcdaea640bb214aa9edb35a1f105e46d

Contents?: true

Size: 1006 Bytes

Versions: 2

Compression:

Stored size: 1006 Bytes

Contents

require 'spec_helper'

describe Kruskal::Tree do
  let(:forest) { Kruskal::Forest.new }

  describe '#==' do
    it 'compares content' do
      t1 = forest.new_tree('a', 'b')
      t2 = forest.new_tree('a', 'b')
      t3 = forest.new_tree('a', 'c')

      expect(t1).to eq t1
      expect(t1).to eq t2
      expect(t1).to_not eq t3
    end

    it 'compares with Array' do
      t1 = forest.new_tree('a', 'b')

      expect(t1).to eq [[0, 'a', 'b']]
    end
  end

  describe '#hash' do
    it 'is the same for same content' do
      t1 = forest.new_tree('a', 'b')
      t2 = forest.new_tree('a', 'b')
      t3 = forest.new_tree('a', 'c')

      expect(t1.hash).to eq t2.hash
      expect(t1.hash).to_not eq t3.hash
    end
  end

  describe 'merge!' do
    it 'adds the content of one tree to the other' do
      t1 = forest.new_tree('a', 'b')
      t2 = forest.new_tree('b', 'c')

      t1.merge!(t2)

      expect(t1).to include [0, 'a', 'b']
      expect(t1).to include [0, 'b', 'c']
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kruskal-0.1.1 spec/lib/kruskal/tree_spec.rb
kruskal-0.1.0 spec/lib/kruskal/tree_spec.rb