<commit_before>require 'spec_helper'

describe Distance do
  describe ".distance_b" do
    context "two members that have never voted on the same thing" do
      it { expect(Distance.distance_b(0, 0)).to eq -1 }
    end

    context "two members always agreeing" do
      it { expect(Distance.distance_b(3, 0)).to eq 0 }
      it { expect(Distance.distance_b(10, 0)).to eq 0 }
    end

    context "two members always disagreeing" do
      it { expect(Distance.distance_b(0, 3)).to eq 1 }
      it { expect(Distance.distance_b(0, 10)).to eq 1 }
    end

    context "two members agreeing half the time" do
      it { expect(Distance.distance_b(3, 3)).to eq 0.5 }
      it { expect(Distance.distance_b(10, 10)).to eq 0.5 }
    end

    it { expect(Distance.distance_b(3, 1)).to eq 0.25 }
  end

  describe ".distance_a" do
    context "no absent votes" do
      it { expect(Distance.distance_a(3, 1, 0)).to eq Distance.distance_b(3, 1)}
    end

    context "only absent votes" do
      it "should see them as neither agreeing or disagreeing" do
        expect(Distance.distance_a(0, 0, 3)).to eq 0.5
      end
    end

    # With 5 absent votes versus 1 agree vote we are half way between agreeing completely (0)
    # and what we would get by both parties being absent all the time (0.5)
    it { expect(Distance.distance_a(1, 0, 5)).to eq 0.25}
    # Similarly here for disagreeing
    it { expect(Distance.distance_a(0, 1, 5)).to eq 0.75}
  end
end<commit_msg>Test points methods<commit_after>require 'spec_helper'

describe Distance do
  describe ".distance_b" do
    context "two members that have never voted on the same thing" do
      it { expect(Distance.distance_b(0, 0)).to eq -1 }
    end

    context "two members always agreeing" do
      it { expect(Distance.distance_b(3, 0)).to eq 0 }
      it { expect(Distance.distance_b(10, 0)).to eq 0 }
    end

    context "two members always disagreeing" do
      it { expect(Distance.distance_b(0, 3)).to eq 1 }
      it { expect(Distance.distance_b(0, 10)).to eq 1 }
    end

    context "two members agreeing half the time" do
      it { expect(Distance.distance_b(3, 3)).to eq 0.5 }
      it { expect(Distance.distance_b(10, 10)).to eq 0.5 }
    end

    it { expect(Distance.distance_b(3, 1)).to eq 0.25 }
  end

  describe ".distance_a" do
    context "no absent votes" do
      it { expect(Distance.distance_a(3, 1, 0)).to eq Distance.distance_b(3, 1)}
    end

    context "only absent votes" do
      it "should see them as neither agreeing or disagreeing" do
        expect(Distance.distance_a(0, 0, 3)).to eq 0.5
      end
    end

    # With 5 absent votes versus 1 agree vote we are half way between agreeing completely (0)
    # and what we would get by both parties being absent all the time (0.5)
    it { expect(Distance.distance_a(1, 0, 5)).to eq 0.25}
    # Similarly here for disagreeing
    it { expect(Distance.distance_a(0, 1, 5)).to eq 0.75}
  end

  describe "#votes_points" do
    # TODO Not yet testing strong votes
    let(:distance) { Distance.new(1, 0, 2, 0, 3, 0) }
    it { expect(distance.votes_points(:same)).to eq 10}
    it { expect(distance.votes_points(:differ)).to eq 0}
    it { expect(distance.votes_points(:absent)).to eq 3}
    it { expect(distance.votes_points(:samestrong)).to eq 0}
    it { expect(distance.votes_points(:differstrong)).to eq 0}
    it { expect(distance.votes_points(:absentstrong)).to eq 0}
  end

  describe "#possible_votes_points" do
    # TODO Not yet testing strong votes
    let(:distance) { Distance.new(1, 0, 2, 0, 3, 0) }
    it { expect(distance.possible_votes_points(:same)).to eq 10}
    it { expect(distance.possible_votes_points(:differ)).to eq 20}
    it { expect(distance.possible_votes_points(:absent)).to eq 6}
    it { expect(distance.possible_votes_points(:samestrong)).to eq 0}
    it { expect(distance.possible_votes_points(:differstrong)).to eq 0}
    it { expect(distance.possible_votes_points(:absentstrong)).to eq 0}
  end
end
{'fraction_non_alphanumeric': 0.11329305135951662, 'fraction_numerical': 0.036505538771399795, 'mean_word_length': 3.1001031991744066, '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': '4089237', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1280, 'n_words': 425}