Sha256: f069b53b0a610362bc9683abe7e7d4b9effff32106ddf2b85a6ce7f30a0e7497

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

require File.expand_path( File.dirname(__FILE__) + '/spec_helper' )
require File.expand_path( File.dirname(__FILE__) + '/transmem_spec_shared' )
require 'transmem'

# turns all string keys into symbol keys
def string_to_symbol(hash)
  if hash.is_a? Hash
    hash.each do |k,v|
      hash[k.to_sym] = hash.delete(k)
      if v.is_a? Hash
        string_to_symbol(v)
      elsif v.is_a? Array
        v.each do |armemb|
          string_to_symbol(armemb)
        end
      end
    end
  end
end

describe TransmemIndex, "determining filetypes" do
  before(:each) do
    @files = %w(toppred.small.out toppred.xml.out phobius.small.small.txt phobius.small.noheader.txt).map {|f| Tfiles + '/' + f }
    @types = %w(toppred toppred phobius phobius).map {|v| v.to_sym }
    @classes = %w(TopPred TopPred Phobius Phobius).map {|v| v.to_sym }
  end
  it 'figures out the filetype' do
    @files.zip(@types) do |file,tp|
      TransmemIndex.filetype(file).should == tp
    end
  end
  it 'given a file to initalize, returns the right object' do
    objects = @files.zip(@classes) do |file,base_klass|
      obj = TransmemIndex.new(file)
      base = Kernel.const_get(base_klass)
      klass = base.const_get(:Index)
      obj.class.should == klass
    end
  end
end



describe TransmemIndex, "methods" do
  it 'calculates the num of overlapping chars in start/stop seqs' do
    ##########0         1         2         3         4         5         6
    ##########01234567890123456789012345678901234567890123456789012345678901
    ##########   ****         ****                       **   ***
    string = 'ABCDEFG ABCDEFG ABCDEFG CATTITY ABCD EFG CD BCDEFGTTITY BCDEFG'
    ########## ^^^^^^  ^^^^^^  ^^^^^^                     ^^^^^^      ^^^^^^
    #         
    substring = 'BCDEFG'
    ranges = [(3..6), (16..19), (43..44), (48..50)]
    expected = [4, 0, 3, 3, 0]
    class TMshell ; include TransmemIndex ; end
    TMshell.new.num_overlapping_chars(string, ranges, substring).should == expected
  end
end


Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mspire-0.4.9 specs/transmem_spec.rb
mspire-0.3.0 specs/transmem_spec.rb
mspire-0.3.1 specs/transmem_spec.rb
mspire-0.3.9 specs/transmem_spec.rb
mspire-0.4.2 specs/transmem_spec.rb
mspire-0.4.4 specs/transmem_spec.rb
mspire-0.4.7 specs/transmem_spec.rb
mspire-0.4.5 specs/transmem_spec.rb