Sha256: 9789a9ef463a215b1752c211e971a04b42d1add1b0956a213da4e572ef77a3ad

Contents?: true

Size: 1.79 KB

Versions: 14

Compression:

Stored size: 1.79 KB

Contents

require File.join(File.dirname(__FILE__), "../../spec_helper")
include Nudge


describe FloatSqrtInstruction do
  
  it_should_behave_like "every Nudge Instruction"
  
  before(:each) do
    @context = Interpreter.new
    @i1 = FloatSqrtInstruction.new(@context)
  end
  
  describe "\#go" do
    before(:each) do
      @i1 = FloatSqrtInstruction.new(@context)
      @context.clear_stacks
      @float1 = ValuePoint.new("float", 12.12)
    end

    describe "\#preconditions?" do
      it "should check that there are enough parameters" do
        lambda{@i1.preconditions?}.should raise_error
        10.times {@context.stacks[:float].push(@float1)}
        @i1.preconditions?.should == true
      end
    end
    
    describe "\#derive" do
      it "should pop all the arguments" do
        1.times {@context.stacks[:float].push(@float1)}
        @i1.stub!(:cleanup) # and do nothing
        @i1.go
        @context.stacks[:float].depth.should == 0
      end
    end
    
    describe "\#cleanup" do
      describe "should push the result" do
        {[4.0] => 2.0, [94.09] => 9.7}.each do |inputs, expected|
          params = inputs.inspect
          it "should produce #{expected} given #{params}" do
          inputs.each {|i| @context.stacks[:float].push(ValuePoint.new("float", i))}
          @i1.go
          @context.stacks[:float].peek.value.should be_close(expected,0.000001)
        end
        end
      end
    end
    
    it "should raise a NaNResultError when it takes a root of a neg" do
      context = Interpreter.new
      [-6.82, -16.0].each do |i|
        context.stacks[:float].push(ValuePoint.new("float", i))
        lambda{FloatSqrtInstruction.new(context).go}.should_not raise_error
        context.stacks[:error].peek.blueprint.should include("float_sqrt did not return a float")
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
nudge-0.2.9 spec/instructions/float/float_sqrt_spec.rb
nudge-0.2.8 spec/instructions/float/float_sqrt_spec.rb
nudge-0.2.7 spec/instructions/float/float_sqrt_spec.rb
nudge-0.2.6 spec/instructions/float/float_sqrt_spec.rb
nudge-0.2.5 spec/instructions/float/float_sqrt_spec.rb
nudge-0.2.4 spec/instructions/float/float_sqrt_spec.rb
nudge-0.2.3 spec/instructions/float/float_sqrt_spec.rb
nudge-0.2.2 spec/instructions/float/float_sqrt_spec.rb
nudge-0.2.1 spec/instructions/float/float_sqrt_spec.rb
nudge-0.2.0 spec/instructions/float/float_sqrt_spec.rb
nudge-0.1.3 spec/instructions/float/float_sqrt_spec.rb
nudge-0.1.2 spec/instructions/float/float_sqrt_spec.rb
nudge-0.1.1 spec/instructions/float/float_sqrt_spec.rb
nudge-0.1.0 spec/instructions/float/float_sqrt_spec.rb