Sha256: c634ce016cfbda9e4ea00c9af0710bbb6f6ad5fa58b9aeead2dc6fea76fc090f

Contents?: true

Size: 1.7 KB

Versions: 4

Compression:

Stored size: 1.7 KB

Contents

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

include Fathom

describe DataNode do

  before do
    @values = [1,2,3,4,5]
    @opts = {:values => @values}
    @dn = DataNode.new(@opts)
    @vector = GSL::Vector.ary_to_gv(@values)
  end
  
  it "should initialize requiring values in the options" do
    lambda{DataNode.new}.should raise_error(/values/)
    lambda{DataNode.new(:values => @values)}.should_not raise_error
  end
  
  it "should make the values readable" do
    @dn.values.should eql(@values)
  end
  
  it "should allow an optional name for the node" do
    @dn = DataNode.new(:values => @values, :name => "Demo Name")
    @dn.name.should eql("Demo Name")
  end
  
  # Note, the distributions aren't defined here yet, so this will eventually be
  # Some sort of Fathom::Distribution::Constant eventually.
  it "should take an optional distribiution" do
    @dn = DataNode.new(@opts.merge(:distribution => :some_distribution))
    @dn.distribution.should eql(:some_distribution)
  end

  it "should create a vector from the values" do
    @dn.vector.should ==(@vector)
  end
  
  it "should provide the standard deviation" do
    @dn.standard_deviation.should ==(@vector.sd)
  end
  
  it "should alias sd and std for standard_deviation" do
    @dn.sd.should eql(@dn.standard_deviation)
    @dn.std.should eql(@dn.standard_deviation)
  end
  
  it "should be able to produce the mean" do
    @dn.mean.should eql(@vector.mean)
  end

  it "should generate a random variable that fits the data's distribution" do
    @dn.rand.should be_a(Float)
  end
  
  it "should have a name_sym method" do
    dn = DataNode.new(:name => "Demo Node", :values => [1,2,3])
    dn.name_sym.should eql(:demo_node)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fathom-0.2.2 spec/fathom/data_node_spec.rb
fathom-0.2.1 spec/fathom/data_node_spec.rb
fathom-0.2.0 spec/fathom/data_node_spec.rb
fathom-0.1.0 spec/fathom/data_node_spec.rb