Sha256: 2d2c97a5f211c7bc3f142473e26e8cfd4936053e894fb97409fb8a1999fa4638
Contents?: true
Size: 1.98 KB
Versions: 12
Compression:
Stored size: 1.98 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') include Fathom describe ValueDescription do before(:all) do @r1 = PlausibleRange.new(:min => 1, :max => 3, :name => 'r1') @r2 = PlausibleRange.new(:min => 1, :max => 3, :name => 'r2') @r3 = PlausibleRange.new(:min => 1, :max => 3, :name => 'r3') @r4 = PlausibleRange.new(:min => 1, :max => 3, :name => 'r4') end before do @vd = ValueDescription.new end it "should be able to initialize with no nodes" do @vd.nodes.should be_empty end it "should be able to take a set of nodes to work with" do vd = ValueDescription.new @r1, @r2, @r3, @r4 vd.nodes.should eql([@r1, @r2, @r3, @r4]) end it "should respond to the names of the nodes being added" do vd = ValueDescription.new @r1, @r2 vd.r1.should be_a(Float) vd.r2.should be_a(Float) end it "should be able to add a node with add_node" do @vd.add_node(@r3) @vd.r3.should be_a(Float) end it "should be able to add a node with an alternative value method" do @vd.add_node(@r3, :name) @vd.r3.should eql('r3') end it "should be able to initialize with a hash, to define the value methods" do vd = ValueDescription.new @r1 => :rand, @r2 => :name vd.r1.should be_a(Float) vd.r2.should eql('r2') end it "should convert node names to lower case, underscore values" do pr = PlausibleRange.new(:min => 1, :max => 3, :name => 'Test Node') vd = ValueDescription.new pr => :name vd.test_node.should eql('Test Node') end it "should respond to process, which by default just adds up the values of the nodes" do vd = ValueDescription.new @r1, @r2 output = vd.process sum = vd.last_process.values.inject(0.0) {|s, e| s += e} output.should eql(sum) end it "should be able to take an optional block at initialization" do vd = ValueDescription.new(@r1 => :name) {|obj| obj.r1 } output = vd.process output.should eql('r1') end end
Version data entries
12 entries across 12 versions & 1 rubygems