Sha256: dbb58814548e7d3016d11b3d81b2352bb5a78b06e0e0e922c5c4d3febfd22034

Contents?: true

Size: 1.69 KB

Versions: 12

Compression:

Stored size: 1.69 KB

Contents

require "spec_helper"

describe "construction of a Node" do
  it "using the properties" do
    n = Node.new
    n.index = 11
    n.value = 0.11
    n.index.should == 11
    n.value.should be_within(0.0001).of(0.11)
  end

  it "using the :[] method" do
    n = Node[12, 0.12]
    n.index.should == 12
    n.value.should be_within(0.00001).of(0.12)
  end

  it "using the constructor parameters" do
    n = Node.new(14, 0.14)
    n.index.should == 14
    n.value.should be_within(0.0001).of(0.14)
  end
end

describe "A Node" do
  before do
    @node = Node.new
  end

  it "can be created" do
    @node.should_not be_nil
  end

  it "does not segfault on setting properties" do
    @node.index = 99
    @node.index.should == 99
    @node.value = 3.141
    @node.value.should be_within(0.00001).of(3.141)
  end

  it "has inited properties" do
    @node.index.should == 0
    @node.value.should be_within(0.00001).of(0)
  end

  it "class can create nodes from an array" do
    ary = Node.features([0.1, 0.2, 0.3, 0.4, 0.5])
    ary.map {|n| n.class.should == Node}
    ary.map {|n| n.value }.should == [0.1, 0.2, 0.3, 0.4, 0.5]
  end

  it "class can create nodes from variable parameters" do
    ary = Node.features(0.1, 0.2, 0.3, 0.4, 0.5)
    ary.map {|n| Node.should === n }
    ary.map {|n| n.value }.should == [0.1, 0.2, 0.3, 0.4, 0.5]
  end

  it "class can create nodes from hash" do
    ary = Node.features(3=>0.3, 5=>0.5, 6=>0.6, 10=>1.0)
    ary.map {|n| n.class.should == Node}
    ary.map {|n| n.value }.sort.should == [0.3, 0.5, 0.6, 1.0]
    ary.map {|n| n.index }.sort.should == [3, 5, 6, 10]
  end

  it "implements a value-like equality, not identity-notion" do
    Node[1, 0.1].should == Node[1, 0.1]
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rb-libsvm-1.1.5 spec/node_spec.rb
rb-libsvm-1.1.4 spec/node_spec.rb
rb-libsvm-1.1.3 spec/node_spec.rb
rb-libsvm-1.1.2 spec/node_spec.rb
rb-libsvm-1.1.1 spec/node_spec.rb
rb-libsvm-1.1.0 spec/node_spec.rb
rb-libsvm-1.0.11 spec/node_spec.rb
rb-libsvm-1.0.10 spec/node_spec.rb
rb-libsvm-1.0.9 spec/node_spec.rb
rb-libsvm-1.0.8 spec/node_spec.rb
rb-libsvm-1.0.7 spec/node_spec.rb
rb-libsvm-1.0.6 spec/node_spec.rb