<commit_before>require 'minitest/autorun'
require 'minitest/spec'
require 'bitvector'

module BitVector
  describe BitVector do
    let(:number) { 0 }
    let(:bit_vector) { BitVector.new number }

    describe "#to_s" do
      subject { bit_vector.to_s }

      describe "for an empty vector" do
        let(:bit_vector) { BitVector.new }

        it "returns all zeros" do
          subject.must_equal("00000000000000000000000000000000")
        end
      end

      describe "with a known number" do
        let(:number) { 0b101 }

        it "returns a formatted string" do
          subject.must_equal("00000000000000000000000000000101")
        end
      end
    end

    describe '#[]=' do
      describe "with a too large index" do
        let(:index) { bit_vector.size + 1 }

        it "raises" do
          lambda { bit_vector[index] = 1 }.must_raise(ArgumentError)
        end
      end

      describe "with a bit set" do
        let(:number) { 0b100 }

        subject { bit_vector[2] }

        describe "when set to 0" do
          before do
            bit_vector[2] = 0
          end

          it "clears bit" do
            subject.must_equal 0
          end
        end

        describe "when set to false" do
          before do
            bit_vector[2] = false
          end

          it "clears bit" do
            subject.must_equal 0
          end
        end
      end

      describe "with no bits set" do
        let(:number) { 0b0 }

        subject { bit_vector[0] }

        describe "when set to 1" do
          before do
            bit_vector[0] = 1
          end

          it "sets bit" do
            subject.must_equal 1
          end
        end

        describe "when set to true" do
          before do
            bit_vector[0] = true
          end

          it "sets bit" do
            subject.must_equal 1
          end
        end
      end
    end

    describe '[]' do
      let(:number) { 0b011 }

      it "returns values at given positions" do
        bit_vector[0].must_equal 1
        bit_vector[1].must_equal 1
        bit_vector[2].must_equal 0
      end

      describe "with a too large index" do
        let(:index) { bit_vector.size + 1 }

        it "raises" do
          lambda { bit_vector[index] }.must_raise(ArgumentError)
        end
      end
    end

    describe '#to_i' do
      subject { bit_vector.to_i }

      before do
        bit_vector[2] = 1
      end

      it 'returns integer representation of vector' do
        subject.must_equal(4)
      end
    end

    describe "#size" do
      subject { bit_vector.size }

      it "returns the default size" do
        subject.must_equal 32
      end
    end

    describe "#==" do
      let(:other_number) { bit_vector.number }
      let(:other_size) { bit_vector.size }<commit_msg>Fix off by one error in spec<commit_after>require 'minitest/autorun'
require 'minitest/spec'
require 'bitvector'

module BitVector
  describe BitVector do
    let(:number) { 0 }
    let(:bit_vector) { BitVector.new number }

    describe "#to_s" do
      subject { bit_vector.to_s }

      describe "for an empty vector" do
        let(:bit_vector) { BitVector.new }

        it "returns all zeros" do
          subject.must_equal("00000000000000000000000000000000")
        end
      end

      describe "with a known number" do
        let(:number) { 0b101 }

        it "returns a formatted string" do
          subject.must_equal("00000000000000000000000000000101")
        end
      end
    end

    describe '#[]=' do
      describe "with a too large index" do
        let(:index) { bit_vector.size }

        it "raises" do
          lambda { bit_vector[index] = 1 }.must_raise(ArgumentError)
        end
      end

      describe "with a bit set" do
        let(:number) { 0b100 }

        subject { bit_vector[2] }

        describe "when set to 0" do
          before do
            bit_vector[2] = 0
          end

          it "clears bit" do
            subject.must_equal 0
          end
        end

        describe "when set to false" do
          before do
            bit_vector[2] = false
          end

          it "clears bit" do
            subject.must_equal 0
          end
        end
      end

      describe "with no bits set" do
        let(:number) { 0b0 }

        subject { bit_vector[0] }

        describe "when set to 1" do
          before do
            bit_vector[0] = 1
          end

          it "sets bit" do
            subject.must_equal 1
          end
        end

        describe "when set to true" do
          before do
            bit_vector[0] = true
          end

          it "sets bit" do
            subject.must_equal 1
          end
        end
      end
    end

    describe '[]' do
      let(:number) { 0b011 }

      it "returns values at given positions" do
        bit_vector[0].must_equal 1
        bit_vector[1].must_equal 1
        bit_vector[2].must_equal 0
      end

      describe "with a too large index" do
        let(:index) { bit_vector.size }

        it "raises" do
          lambda { bit_vector[index] }.must_raise(ArgumentError)
        end
      end
    end

    describe '#to_i' do
      subject { bit_vector.to_i }

      before do
        bit_vector[2] = 1
      end

      it 'returns integer representation of vector' do
        subject.must_equal(4)
      end
    end

    describe "#size" do
      subject { bit_vector.size }

      it "returns the default size" do
        subject.must_equal 32
      end
    end

    describe "#==" do
      let(:other_number) { bit_vector.number }
      let(:other_size) { bit_vector.size }
{'fraction_non_alphanumeric': 0.07570641549671228, 'fraction_numerical': 0.03767549315798827, 'mean_word_length': 1.5616750113791533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '2847924', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1608, 'n_words': 510}