Sha256: 271cf41165c845e6f2f7de55592970ffb9b7362e408ea1a11481b21de738c871

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

RSpec.describe(PatronusFati::BitHelper) do
  context '#count_consecutive_bits' do
    let(:test_set) do
      [
        { bits: "00000000", answer: 0 },
        { bits: "11111111", answer: 8 },
        { bits: "11001111", answer: 4 },
        { bits: "10101010", answer: 1 }
      ]
    end

    it 'should correctly count varying number of consecutive bits in a number' do
      test_set.each do |set|
        num = set[:bits].to_i(2)
        expect(described_class.count_consecutive_bits(num)).to eql(set[:answer])
      end
    end
  end

  context '#largest_bit_overlap' do
    let(:test_set) do
      [
        {
          bit_strings: [
            "000000000000000000000000",
            "000011100000111000001110",
            "001111000011110000111100",
            "111111111111111111111111"
          ],
          answer: 4
        },
        {
          bit_strings: [
            "0000"
          ],
          answer: 0
        },
        {
          bit_strings: [
            "1111111111111111",
            "1111111111111111",
            "0000000000000000"
          ],
          answer: 16
        },
        {
          bit_strings: [],
          answer: 0
        },
        {
          bit_strings: [
            "0000000011111111",
            "1111111100000000"
          ],
          answer: 0
        }
      ]
    end

    it 'should correctly find the longest run of overlapping bits' do
      test_set.each do |set|
        nums = set[:bit_strings].map { |bs| bs.to_i(2) }
        expect(described_class.largest_bit_overlap(nums)).to eql(set[:answer])
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
patronus_fati-1.3.8 spec/patronus_fati/bit_helper_spec.rb
patronus_fati-1.3.7 spec/patronus_fati/bit_helper_spec.rb
patronus_fati-1.3.6 spec/patronus_fati/bit_helper_spec.rb
patronus_fati-1.3.5 spec/patronus_fati/bit_helper_spec.rb
patronus_fati-1.3.4 spec/patronus_fati/bit_helper_spec.rb
patronus_fati-1.3.3 spec/patronus_fati/bit_helper_spec.rb
patronus_fati-1.3.2 spec/patronus_fati/bit_helper_spec.rb