<commit_before>shared_examples 'a function that joins many variables with same operation' do |arguments|
  it_behaves_like 'a function that knows how to calculate', arguments
  it_behaves_like 'a function that knows how to write to tex', arguments
end

shared_examples 'a function that knows how to calculate' do |arguments|
  %w(calculated).each do |key|
    let(key) { arguments[key.to_sym]  }
  end
  let(:variables) do
    (1..4).map do |i|
      Danica::Variable.new(name: "X#{i}", value: numeric_variables[i-1])
    end
  end
  let(:numeric_variables){ (1..4).to_a }
  let(:subject) do
    described_class.new(variables: variables)
  end

  describe 'to_f' do
    it 'returns the sum of variables value' do
      expect(subject.to_f).to eq(calculated)
    end

    it do
      expect(subject.to_f).to be_a(Float)
    end

    context 'when one variable is a number' do
      let(:variables) { (1..4) }

      it do
        expect(subject.to_f).to eq(calculated)
      end

      it do
        expect(subject.to_f).to be_a(Float)
      end
    end
  end
end

shared_examples 'a function that knows how to write to tex' do |arguments|
  %w(numeric_variables tex_integer_expected tex_expected tex_float_expected).each do |key|
    let(key) { arguments[key.to_sym]  }
  end
  let(:subject) do
    described_class.new(variables: variables)
  end

  describe 'to_tex' do
    context 'when variables have no value' do
      let(:variables) do
        (1..4).map do |i|
          Danica::Variable.new(name: "X#{i}")
        end
      end

      it 'outputs a latex format' do
        expect(subject.to_tex).to eq(tex_expected)
      end

      context 'when some variables have values' do
        let(:numeric_variables_index) { 1 }
        before do
          (0..numeric_variables_index).each do |i|
            variables[i].value = numeric_variables[i]
          end
        end

        it 'outputs a latex format with colapsed numbers' do
          expect(subject.to_tex).to eq(tex_integer_expected)
        end

        context 'when numeric variables sum is a float value' do
          let(:numeric_variables_index) { 2 }

          it 'outputs a latex format with colapsed numbers' do
            expect(subject.to_tex).to eq(tex_float_expected)
          end
        end
      end
    end
  end
end<commit_msg>Refactor shared example<commit_after>shared_examples 'a function that joins many variables with same operation' do |arguments|
  it_behaves_like 'a function that knows how to calculate', arguments
  it_behaves_like 'a function that knows how to write to tex', arguments
end

shared_examples 'a function that knows how to calculate' do |arguments|
  %w(calculated).each do |key|
    let(key) { arguments[key.to_sym]  }
  end
  let(:variables) do
    (1..4).map do |i|
      Danica::Variable.new(name: "X#{i}", value: numeric_variables[i-1])
    end
  end
  let(:numeric_variables){ (1..4).to_a }
  let(:subject) do
    described_class.new(variables: variables)
  end

  describe 'to_f' do
    it 'returns the sum of variables value' do
      expect(subject.to_f).to eq(calculated)
    end

    it do
      expect(subject.to_f).to be_a(Float)
    end

    context 'when one variable is a number' do
      let(:variables) { (1..4) }

      it do
        expect(subject.to_f).to eq(calculated)
      end

      it do
        expect(subject.to_f).to be_a(Float)
      end
    end
  end
end

shared_examples 'a function that knows how to write to tex' do |arguments|
  %w(numeric_variables tex_integer_expected tex_expected tex_float_expected).each do |key|
    let(key) { arguments[key.to_sym]  }
  end
  let(:subject) do
    described_class.new(variables: variables)
  end

  describe 'to_tex' do
    let(:variables) do
      (1..4).map do |i|
        Danica::Variable.new(name: "X#{i}")
      end
    end

    context 'when variables have no value' do
      it 'outputs a latex format' do
        expect(subject.to_tex).to eq(tex_expected)
      end
    end

    context 'when some variables have values' do
      let(:numeric_variables_index) { 1 }
      before do
        (0..numeric_variables_index).each do |i|
          variables[i].value = numeric_variables[i]
        end
      end

      it 'outputs a latex format with colapsed numbers' do
        expect(subject.to_tex).to eq(tex_integer_expected)
      end

      context 'when numeric variables sum is a float value' do
        let(:numeric_variables_index) { 2 }

        it 'outputs a latex format with colapsed numbers' do
          expect(subject.to_tex).to eq(tex_float_expected)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09217391304347826, 'fraction_numerical': 0.0052173913043478265, 'mean_word_length': 2.654487688641779, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3211965', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1425, 'n_words': 445}