Sha256: f10c67011a6b12a94912a93f5cb105552b3688a153f8f399bf64c9a0aaa988bd

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

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

include Fathom

describe MCNode do
  
  before(:all) do
    @fields = [:value_result]
  end
  
  before do 
    @vd = lambda{|n| {:value_result => 1}}
    @mcn = MCNode.new(:value_description => @vd)
  end
  
  it "should be a type of Node" do
    MCNode.ancestors.should be_include(Fathom::Node)
  end
  
  it "should use a value_description from the command-line arguments" do
    mcn = MCNode.new(:value_description => @vd)
    mcn.value_description.should eql(@vd)
  end
  
  it "should be able to take a block instead of a named lamda for the value description" do
    mcn = MCNode.new {|n| {:value_result => 1}}
    mcn.value_description.should be_a(Proc)
  end
  
  it "should require a value_description from either a parameter or a block passed in" do
    lambda{MCNode.new}.should raise_error(/value_description/)
  end
  
  it "should process with the default number of runs at 10,000", :slow => true do
    lambda{@mcn.process}.should_not raise_error
    @mcn.samples_taken.should eql(10_000)
  end
  
  it "should call the value_description block each time it is processed" do
    @vd.should_receive(:call).exactly(3).times.with(@mcn).and_return({:value_result => 1})
    @mcn.process(3)
  end
  
  it "should define children nodes for all keys in the result set" do
    @mcn.process(1)
    @mcn.value_result.should be_a(Node)
    @mcn.value_result.values.should eql([1])
    @mcn.value_result.vector.should be_a(GSL::Vector)
  end
  
  it "should be resetable" do
    @mcn.process(1)
    @mcn.reset!
    lambda{@mcn.process(1)}.should_not raise_error
  end
  
  it "should expose the fields from the samples" do
    @mcn.process(1)
    sort_array_of_symbols(@mcn.fields).should eql(@fields)
  end
  
  
end
def sort_array_of_symbols(array)
  array.map {|e| e.to_s}.sort.map {|e| e.to_sym}
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fathom-0.3.0 spec/fathom/mc_node_spec.rb