Sha256: 2f07dc1f4e108ecaee07188e74fbad3f61ae95d09d3a4f88e4afcfcefd59c72b

Contents?: true

Size: 982 Bytes

Versions: 1

Compression:

Stored size: 982 Bytes

Contents

require 'test_helper'
require 'stringio'

class TestBitsCountIO < Test::Unit::TestCase
  TEST_BIT_STRINGS = {
    "1"           => 1,
    "01"          => 1,
    "010"         => 1,
    "011"         => 2,
    "01"*32       => 32,
    "1"*64        => 64,
    "0"<< "1"*63  => 63,
    "01"*64       => 64,
    "0"*512<< "1" => 1
  }

  TEST_METHODS = BitsCount::IO.methods.grep(/population_count/)

  TEST_METHODS.each do |method|
    define_method "test_#{method}" do
      TEST_BIT_STRINGS.each do |binstr, expected_count|
        StringIO.open([binstr].pack("b*"), "rb") do |io|
          assert_equal(expected_count, BitsCount::IO.send(method, io), "Bin sring: #{binstr}")
        end
      end
    end
  end

  def test_benchmark
    io =  StringIO.new(File.binread(Fixtures.large_bin), 'rb')
    Benchmark.bmbm  do |x|
      TEST_METHODS.each do |method|
        x.report("IO.#{method}"){ io.rewind; BitsCount::IO.send(method, io)  }
      end
    end
    io.close
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bits_count-0.0.1 test/bits_count/test_io.rb