Sha256: 6dc925b3184b20e8f7513ec0ff1bf08b7f6e5e6769e6ecf2c274d87f5af1f6fd

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

#encoding: utf-8
require File.join(File.dirname(__FILE__), "../../spec_helper")
include Nudge

describe ProportionFromFloatInstruction do
  
  it_should_behave_like "every Nudge Instruction"
  
  before(:each) do
    @context = Interpreter.new
    @i1 = ProportionFromFloatInstruction.new(@context)
    @context.clear_stacks
  end
  
  it "should check that there are enough parameters" do
    @context.push(:float, "0.234")
    @i1.preconditions?.should == true
  end
  
  it "should raise an error if the preconditions aren't met" do
    @context.clear_stacks # there are no params at all
    lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
  end
  
  it "should successfully run #go only if all preconditions are met" do
    @context.push(:float, "0.22")
    @i1.should_receive(:cleanup)
    @i1.go
  end
  
  it "should create and push the new (expected) value to the right place" do
    @context.push(:float, "0.1")
    @i1.go
    @context.depth(:proportion).should == 1
    @context.peek_value(:proportion).should == 0.1
  end
  
  it "should return a number in [0.0, 1.0]" do
    @context.push(:float, "11.11")
    @i1.go
    @context.depth(:proportion).should == 1
    @context.peek_value(:proportion).should be_close(0.11, 0.000001)
    
    @context.push(:float, "-2.7")
    @i1.go
    @context.peek_value(:proportion).should be_close(0.3, 0.000001)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nudge-0.2.9 spec/instructions/proportion/proportion_from_float_spec.rb