<commit_before># encoding: utf-8

require 'spec_helper'

describe Algebra::Restriction, '#delete' do
  subject { object.delete(other) }

  let(:object)         { described_class.new(operand, predicate)                           }
  let(:operand)        { Relation.new([ attribute ], LazyEnumerable.new([ [ 1 ], [ 2 ] ])) }
  let(:other_relation) { Relation.new([ attribute ], LazyEnumerable.new([ [ 0 ], [ 2 ] ])) }
  let(:attribute)      { Attribute::Integer.new(:id)                                       }
  let(:predicate)      { attribute.gte(1)                                                  }

  shared_examples_for 'Algebra::Restrict#delete' do
    it { should be_instance_of(described_class) }

    its(:operand) { should be_kind_of(Relation) }

    its(:predicate) { should equal(predicate) }

    it 'filters out tuples from the other relation not matching the predicate' do
      should == [ [ 1 ] ]
    end
  end

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

    it_should_behave_like 'Algebra::Restrict#delete'
  end

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

    it_should_behave_like 'Algebra::Restrict#delete'
  end

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

    it_should_behave_like 'Algebra::Restrict#delete'
  end
end
<commit_msg>Fix Restriction#delete spec to kill mutation<commit_after># encoding: utf-8

require 'spec_helper'

describe Algebra::Restriction, '#delete' do
  subject { object.delete(other) }

  let(:object)         { described_class.new(operand, predicate)                           }
  let(:operand)        { Relation.new([ attribute ], LazyEnumerable.new([ [ 1 ], [ 2 ] ])) }
  let(:other_relation) { Relation.new([ attribute ], LazyEnumerable.new([ [ 0 ], [ 2 ] ])) }
  let(:attribute)      { Attribute::Integer.new(:id)                                       }
  let(:predicate)      { attribute.gte(1)                                                  }

  shared_examples_for 'Algebra::Restrict#delete' do
    it { should be_instance_of(described_class) }

    its(:operand) { should be_kind_of(Relation::Operation::Deletion) }

    its(:operand) do
      # test that the expected restriction was passed to the deletion
      subject.left.should equal(operand)
      subject.right.should be_kind_of(described_class)
      subject.right.predicate.should equal(predicate)
    end

    its(:predicate) { should equal(predicate) }

    it 'filters out tuples from the other relation not matching the predicate' do
      should == [ [ 1 ] ]
    end
  end

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

    it_should_behave_like 'Algebra::Restrict#delete'
  end

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

    it_should_behave_like 'Algebra::Restrict#delete'
  end

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

    it_should_behave_like 'Algebra::Restrict#delete'
  end
end

{'fraction_non_alphanumeric': 0.11449371277299801, 'fraction_numerical': 0.004632693580410324, 'mean_word_length': 2.704656862745098, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '250507', 'n_tokens_mistral': 958, 'n_tokens_neox': 903, 'n_words': 212}