<commit_before>require 'spec_helper'
require 'document_merger'

describe "Merge document" do
  subject do
    DocumentMerger.merge(docs)
  end

  context "given 1 document" do
    let(:docs) do
      [
        { "key" => "elmar", "data" => { "length" => "35", "aperture" => "3.5" } }
      ]
    end

    it { is_expected.to eq(docs) }
  end

  context "given 2 different schema document" do
    context "when documents has same key" do
      let(:docs) do
        [
          { "key" => "elmar", "data" => { "length" => "35", "aperture" => "3.5" } },
          { "key" => "elmar", "data" => { "year" => "1954" } },
        ]
      end

      let(:expected) do
        [
          {
            "key" => "elmar",
            "data" => { "length" => "35", "aperture" => "3.5", "year" => "1954" }
          }
        ]
      end

      it { is_expected.to eq(expected) }
    end
  end
end<commit_msg>add test case<commit_after>require 'spec_helper'
require 'document_merger'

describe "Merge document" do
  subject do
    DocumentMerger.merge(docs)
  end

  context "given 1 document" do
    let(:docs) do
      [
        { "key" => "elmar", "data" => { "length" => "35", "aperture" => "3.5" } }
      ]
    end

    it { is_expected.to eq(docs) }
  end

  context "given 2 different schema document" do
    context "when documents has same key" do
      let(:docs) do
        [
          { "key" => "elmar", "data" => { "length" => "35", "aperture" => "3.5" } },
          { "key" => "elmar", "data" => { "year" => "1954" } },
        ]
      end

      let(:expected) do
        [
          {
            "key" => "elmar",
            "data" => { "length" => "35", "aperture" => "3.5", "year" => "1954" }
          }
        ]
      end

      it { is_expected.to eq(expected) }
    end

    context "when documents has NOT same key" do
      let(:docs) do
        [
          { "key" => "elmar", "data" => { "length" => "35", "aperture" => "3.5" } },
          { "key" => "summicron", "data" => { "year" => "1963" } },
        ]
      end

      let(:expected) do
        [
          { "key" => "elmar", "data" => { "length" => "35", "aperture" => "3.5" } },
          { "key" => "summicron", "data" => { "year" => "1963" } },
        ]
      end

      it { is_expected.to eq(expected) }
    end
  end

  context "given 3 different schema document" do
    context "when documents has same key" do
      let(:docs) do
        [
          { "key" => "summicron", "data" => { "length" => "50", "aperture" => "2" } },
          { "key" => "elmar", "data" => { "length" => "35", "aperture" => "3.5" } },
          { "key" => "elmar", "data" => { "year" => "1954" } },
        ]
      end

      let(:expected) do
        [
          {
            "key" => "summicron",
            "data" => { "length" => "50", "aperture" => "2" }
          },
          {
            "key" => "elmar",
            "data" => { "length" => "35", "aperture" => "3.5", "year" => "1954" }
          }
        ]
      end

      it { is_expected.to eq(expected) }
    end

    context "when documents has NOT same key" do
      let(:docs) do
        [
          { "key" => "elmar", "data" => { "length" => "35", "aperture" => "3.5" } },
          { "key" => "summicron", "data" => { "year" => "1963" } },
          { "key" => "noctilux", "data" => { "length" => "50", "aperture" => "1.1" } },
        ]
      end

      let(:expected) do
        [
          { "key" => "elmar", "data" => { "length" => "35", "aperture" => "3.5" } },
          { "key" => "summicron", "data" => { "year" => "1963" } },
          { "key" => "noctilux", "data" => { "length" => "50", "aperture" => "1.1" } },
        ]
      end

      it { is_expected.to eq(expected) }
    end
  end
end
{'fraction_non_alphanumeric': 0.21025915041410634, 'fraction_numerical': 0.028586695164306706, 'mean_word_length': 1.7268754552075747, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 91, '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': '3367584', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1330, 'n_words': 315}