<commit_before>require 'spec_helper'

describe Datapipes::Tube do
  describe 'composable' do
    let(:tube_a) do
      Class.new(Datapipes::Tube) do
        def run(data)
          data + 2
        end
      end.new
    end

    let(:tube_b) do
      Class.new(Datapipes::Tube) do
        def run(data)
          data * 3
        end
      end.new
    end

    let(:tube_c) do
      Class.new(Datapipes::Tube) do
        def run(data)
          data + 4
        end
      end.new
    end

    subject { tube_a >> tube_b >> tube_c }

    it 'composes' do
      expect(subject.run(4)).to eq 22
    end
  end
end<commit_msg>Add associative law for tube<commit_after>require 'spec_helper'

describe Datapipes::Tube do
  describe 'composable' do
    let(:tube_a) do
      Class.new(Datapipes::Tube) do
        def run(data)
          data + 2
        end
      end.new
    end

    let(:tube_b) do
      Class.new(Datapipes::Tube) do
        def run(data)
          data * 3
        end
      end.new
    end

    let(:tube_c) do
      Class.new(Datapipes::Tube) do
        def run(data)
          data + 4
        end
      end.new
    end

    subject { tube_a >> tube_b >> tube_c }

    it 'composes' do
      expect(subject.run(4)).to eq 22
    end

    describe 'associative law' do
      let(:a) { (tube_a >> tube_b) >> tube_c }
      let(:b) { tube_a >> (tube_b >> tube_c) }

      it 'keeps' do
        expect(a.run(5)).to eq b.run(5)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10443686006825939, 'fraction_numerical': 0.00955631399317406, 'mean_word_length': 1.6948529411764706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '6914095', 'n_tokens_mistral': 543, 'n_tokens_neox': 509, 'n_words': 131}