Sha256: a9abab7379ff30996d22c977c30f9bbd29895d8a66b639863ff3a879a655aae7

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Relation, '#replace' do
  subject { object.replace(other) }

  let(:object)         { described_class.new(header, [ [ 1 ] ]) }
  let(:other_relation) { described_class.new(header, [ [ 2 ] ]) }
  let(:header)         { [ [ :id, Integer ] ]                   }

  shared_examples_for 'Relation#replace' do
    it { should be_instance_of(Relation::Operation::Insertion) }

    its(:header) { should == header }

    it 'returns the expected tuples' do
      should == other
    end

    it 'applies the left operations in the correct sequence' do
      subject = self.subject.left
      subject.should be_instance_of(Relation::Operation::Deletion)
      subject.left.should equal(object)
      subject.right.should be_instance_of(Algebra::Difference)
      subject.right.left.should equal(object)
      subject.right.right.should eql(other_relation)
    end

    it 'applies the right operations in the correct sequence' do
      subject = self.subject.right
      subject.should be_instance_of(Algebra::Difference)
      subject.left.should eql(other_relation)
      subject.right.should equal(object)
    end
  end

  context 'with a relation' do
    let(:other) { other_relation }

    it_should_behave_like 'Relation#replace'
  end

  context 'with an array of tuples' do
    let(:other) { other_relation.to_a }

    it_should_behave_like 'Relation#replace'
  end

  context 'with an array of arrays' do
    let(:other) { other_relation.map(&:to_ary) }

    it_should_behave_like 'Relation#replace'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axiom-0.1.0 spec/unit/axiom/relation/replace_spec.rb