<commit_before>require 'spec_helper'

describe Twigg::PairMatrix do
  subject { described_class.new(commit_set) }

  describe '#[]' do
    context 'with an empty matrix' do
      let(:commit_set) { [] }

      it 'returns zero for solo commits' do
        expect(subject['<NAME>']['<NAME>']).to be_zero
      end

      it 'returns zero for pair commits' do
        expect(subject['<NAME>']['<NAME>']).to be_zero
      end
    end

    context 'for a (non-)contributor who has not made any commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME> & <NAME>'),
        ])
      end

      it 'returns zero solo commits' do
        expect(subject['John Nobody']['John Nobody']).to be_zero
      end

      it 'returns zero commits as pairer' do
        expect(subject['John Nobody']['Guybrush Threepwood']).to be_zero
      end

      it 'returns zero commits as pairee' do
        expect(subject['Guybrush Threepwood']['John Nobody']).to be_zero
      end
    end

    context 'for a contributor who has made only solo commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME> & <NAME>'),
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME>'),
        ])
      end

      it 'returns the count of solo commits' do
        expect(subject['Old Greg']['Old Greg']).to eq(2)
      end

      it 'returns zero commits as pairer' do
        expect(subject['Old Greg']['<NAME>']).to be_zero
      end

      it 'returns zero commits as pairee' do
        expect(subject['<NAME>']['Old Greg']).to be_zero
      end
    end

    context 'for a contributor who has made only pair commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME> & <NAME>'),
          build(:commit, author: '<NAME> + <NAME>'),
          build(:commit, author: '<NAME>, <NAME> and <NAME>'),
          build(:commit, author: '<NAME>'),
        ])
      end

      it 'returns the count of pair commits as pairer' do
        expect(subject['<NAME>']['<NAME>']).to eq(2)
        expect(subject['<NAME>']['<NAME>']).to eq(1)
        expect(subject['<NAME>con']['<NAME>']).to eq(1)
        expect(subject['<NAME>con']['Douglas K Eckthorpe']).to be_zero
      end

      it 'returns the count of pair commits as pairee' do
        expect(subject['<NAME>']['<NAME>']).to eq(2)
        expect(subject['Jeeves Sumner']['<NAME>']).to eq(1)
        expect(subject['Kyle Largs']['<NAME>con']).to eq(1)
        expect(subject['Douglas K Eckthorpe']['<NAME>niecon']).to be_zero
      end

      it 'returns zero solo commits' do
        expect(subject['Xavier Minniecon']['<NAME>']).to be_zero
      end
    end

    context 'for a contributor who has made both solo and pair commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME> and <NAME>'),
          build(:commit, author: '<NAME> & <NAME>'),
        ])
      end

      it 'returns the count of pair commits as pairer' do
        expect(subject['Kim Mason']['<NAME>']).to eq(1)
        expect(subject['Kim Mason']['<NAME>er']).to be_zero
      end

      it 'returns the count of pair commits as pairee' do
        expect(subject['Nebs Petrovic']['<NAME>']).to eq(1)
        expect(subject['<NAME>er']['Kim Mason']).to be_zero
      end

      it 'returns the count of solo commits' do
        expect(subject['Kim Mason']['Kim Mason']).to eq(2)
      end
    end
  end
end<commit_msg>Add spec coverage for other PairMatrix methods<commit_after>require 'spec_helper'

describe Twigg::PairMatrix do
  subject { described_class.new(commit_set) }

  describe '#[]' do
    context 'with an empty matrix' do
      let(:commit_set) { [] }

      it 'returns zero for solo commits' do
        expect(subject['Royce Royson']['Royce Royson']).to be_zero
      end

      it 'returns zero for pair commits' do
        expect(subject['<NAME>']['Rooptag Googliogg']).to be_zero
      end
    end

    context 'for a (non-)contributor who has not made any commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME> & <NAME>'),
        ])
      end

      it 'returns zero solo commits' do
        expect(subject['John Nobody']['John Nobody']).to be_zero
      end

      it 'returns zero commits as pairer' do
        expect(subject['John Nobody']['Guybrush Threepwood']).to be_zero
      end

      it 'returns zero commits as pairee' do
        expect(subject['Guybrush Threepwood']['John Nobody']).to be_zero
      end
    end

    context 'for a contributor who has made only solo commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME> & <NAME>'),
          build(:commit, author: 'Old Greg'),
          build(:commit, author: 'Old Greg'),
        ])
      end

      it 'returns the count of solo commits' do
        expect(subject['Old Greg']['Old Greg']).to eq(2)
      end

      it 'returns zero commits as pairer' do
        expect(subject['Old Greg']['<NAME>']).to be_zero
      end

      it 'returns zero commits as pairee' do
        expect(subject['<NAME>']['<NAME>']).to be_zero
      end
    end

    context 'for a contributor who has made only pair commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME> & <NAME>'),
          build(:commit, author: '<NAME> + <NAME>'),
          build(:commit, author: '<NAME>, <NAME> and <NAME>'),
          build(:commit, author: '<NAME>'),
        ])
      end

      it 'returns the count of pair commits as pairer' do
        expect(subject['<NAME>']['<NAME>']).to eq(2)
        expect(subject['<NAME>']['<NAME>']).to eq(1)
        expect(subject['<NAME>']['<NAME>']).to eq(1)
        expect(subject['<NAME>']['<NAME>']).to be_zero
      end

      it 'returns the count of pair commits as pairee' do
        expect(subject['<NAME>']['<NAME>']).to eq(2)
        expect(subject['<NAME>']['<NAME>']).to eq(1)
        expect(subject['<NAME>']['<NAME>']).to eq(1)
        expect(subject['<NAME>']['<NAME>']).to be_zero
      end

      it 'returns zero solo commits' do
        expect(subject['<NAME>']['<NAME>']).to be_zero
      end
    end

    context 'for a contributor who has made both solo and pair commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME> and <NAME>'),
          build(:commit, author: '<NAME> & <NAME>'),
        ])
      end

      it 'returns the count of pair commits as pairer' do
        expect(subject['Kim Mason']['Nebs Petrovic']).to eq(1)
        expect(subject['Kim Mason']['Tony Wooster']).to be_zero
      end

      it 'returns the count of pair commits as pairee' do
        expect(subject['Nebs Petrovic']['Kim Mason']).to eq(1)
        expect(subject['Tony Wooster']['Kim Mason']).to be_zero
      end

      it 'returns the count of solo commits' do
        expect(subject['Kim Mason']['Kim Mason']).to eq(2)
      end
    end
  end

  describe '#authors' do
    let(:commit_set) do
      Twigg::CommitSet.new([
        build(:commit, author: '<NAME>'),
        build(:commit, author: '<NAME>'),
        build(:commit, author: '<NAME> & <NAME>'),
        build(:commit, author: '<NAME>, <NAME> + <NAME>'),
      ])
    end

    it 'returns the list of authors in sorted order' do
      expect(subject.authors).to eq([
        '<NAME>',
        '<NAME>',
        '<NAME>',
        '<NAME>',
        '<NAME>',
        '<NAME>',
        '<NAME>',
      ])
    end
  end

  describe '#max_solo' do
    context 'with no solo commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME> + <NAME>'),
          build(:commit, author: '<NAME> and <NAME>'),
        ])
      end

      it 'returns zero' do
        expect(subject.max_solo).to be_zero
      end
    end

    context 'with solo commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME> & <NAME>'),
          build(:commit, author: '<NAME> and <NAME>'),
        ])
      end

      it 'returns the maximum solo commit count' do
        expect(subject.max_solo).to eq(2)
      end
    end
  end

  describe '#max_pair' do
    context 'with no pair commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME>'),
        ])
      end

      it 'returns zero' do
        expect(subject.max_pair).to be_zero
      end
    end

    context 'with pair commits' do
      let(:commit_set) do
        Twigg::CommitSet.new([
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME>'),
          build(:commit, author: '<NAME> & <NAME>'),
          build(:commit, author: '<NAME> and <NAME>'),
          build(:commit, author: '<NAME> and <NAME>'),
        ])
      end

      it 'returns the maximum pair commit count' do
        expect(subject.max_pair).to eq(2)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.15475313190862197, 'fraction_numerical': 0.0023160332666596482, 'mean_word_length': 2.41726618705036, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 123, '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': '7046286', 'n_tokens_mistral': 2969, 'n_tokens_neox': 2852, 'n_words': 838}