<commit_before>require 'test_helper'

class FunctionTest < Minitest::Test
  include Lightpipe

  context "Composition tests" do
    should "compose multiple functions into one" do
      add_one      = ->(number) { number + 1 }
      multiply_two = ->(number) { number * 2 }
      composition  = Function.compose [add_one, multiply_two]

      assert_equal 4, composition.call(1)
    end

    should "compose across data types" do
      text    = "This is an <b>example</b> of\n text. it has formatting issues."
      remove_line_feeds = ->(text) { text.gsub(/\n+/, '') }
      remove_markup     = ->(text) { text.gsub(/(<([^>]+)>)/, '') }
      split_sentences   = ->(text) { text.split(/ *\. */) }
      strip             = ->(text) { text.strip }
      capitalize        = ->(text) { text.map(&:capitalize) }
      join              = ->(array) { array.join('. ') }

      composition = Function.compose [ strip,
                                       remove_line_feeds,
                                       remove_markup,
                                       split_sentences,
                                       capitalize,
                                       join ]

      assert_equal "This is an example of text. It has formatting issues", composition.call(text)
    end
  end
end<commit_msg>Added a test case to handle a param list of functions<commit_after>require 'test_helper'

class FunctionTest < Minitest::Test
  include Lightpipe

  context "Composition tests" do
    should "compose multiple functions into one" do
      add_one      = ->(number) { number + 1 }
      multiply_two = ->(number) { number * 2 }
      composition  = Function.compose [add_one, multiply_two]

      assert_equal 4, composition.call(1)
    end

    should "compose across data types" do
      text    = "This is an <b>example</b> of\n text. it has formatting issues."
      remove_line_feeds = ->(text) { text.gsub(/\n+/, '') }
      remove_markup     = ->(text) { text.gsub(/(<([^>]+)>)/, '') }
      split_sentences   = ->(text) { text.split(/ *\. */) }
      strip             = ->(text) { text.strip }
      capitalize        = ->(text) { text.map(&:capitalize) }
      join              = ->(array) { array.join('. ') }

      composition = Function.compose [ strip,
                                       remove_line_feeds,
                                       remove_markup,
                                       split_sentences,
                                       capitalize,
                                       join ]

      assert_equal "This is an example of text. It has formatting issues", composition.call(text)
    end

    should "allow a param list of functions rather than an array of functions" do
      text    = "This is an <b>example</b> of\n text. it has formatting issues."
      remove_line_feeds = ->(text) { text.gsub(/\n+/, '') }
      remove_markup     = ->(text) { text.gsub(/(<([^>]+)>)/, '') }
      split_sentences   = ->(text) { text.split(/ *\. */) }
      strip             = ->(text) { text.strip }
      capitalize        = ->(text) { text.map(&:capitalize) }
      join              = ->(array) { array.join('. ') }

      composition = Function.compose  strip,
                                      remove_line_feeds,
                                      remove_markup,
                                      split_sentences,
                                      capitalize,
                                      join

      assert_equal "This is an example of text. It has formatting issues", composition.call(text)
    end
  end
end
{'fraction_non_alphanumeric': 0.12123745819397994, 'fraction_numerical': 0.002229654403567447, 'mean_word_length': 1.4854570637119113, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7353083', 'n_tokens_mistral': 1023, 'n_tokens_neox': 974, 'n_words': 257}