Sha256: eee4a5b560d28b20843834621624ea3178015897d62c59b4b5797a9490629401

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require "spec_helper"

describe Selector::WithBinaryEncoding do
  it_behaves_like 'a selector'
  let(:simple) { Selector::WithBinaryEncoding.new(:career_level) }

  let(:dictionary) { %w(auto pferd haus hase garten) }
  let(:data) { FactoryGirl.build(:data) }
  let(:vector) { simple.generate_vector(data) }

  before(:each) do
    simple.stubs(:global_dictionary).returns(dictionary)
  end
  it "should build a feature vector for each dataset with the size of the dictionary plus classifications" do
    vector.data.should have(5+4).things
  end
  it "should set 0 if a word from the dictionary NOT exists at the corresponding index" do
    vector.data[0].should eq(0)
  end
  it "should set 1 if a word from the dictionary exists at the corresponding index" do
    vector.data[1].should eq(1)
  end
  it "should set 0's and 1's for each word in the dictionary" do
    vector.data.first(5).should eq([0,1,1,0,1])
  end
  it "should add a n-sized array of 0's and 1's to the results" do
    vector.data.last(4).should eq([0,1,1,1])
  end
  it "should call make_vector" do
    simple.expects(:make_vector).once
    simple.generate_vector(data)
  end
  context "custom dictionary" do
    it "should accept a custom dictionary" do
      vector = simple.generate_vector(data, %w(pferd flasche glas))
      vector.data.should eq([[1,0,0],[0,1,1,1]].flatten)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
svm_helper-0.1.1 spec/selectors/with_binary_encoding_spec.rb