Sha256: 061ffce1e69416e11206dc76e538d6b68c6b813e2e8793d41a8f330803102b86

Contents?: true

Size: 1.59 KB

Versions: 14

Compression:

Stored size: 1.59 KB

Contents

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


describe "IntLessThanQInstruction" do
  
  it_should_behave_like "every Nudge Instruction"
  
  before(:each) do
    @context = Interpreter.new    
    @i1 = IntLessThanQInstruction.new(@context)
    @int1 = ValuePoint.new("int", 1)
    @int2 = ValuePoint.new("int", 2)
  end
  
  
  it "should check that there are enough parameters" do
    6.times {@context.stacks[:int].push(@int1)}
    @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
    5.times {@context.stacks[:int].push(@int1)}
    @i1.should_receive(:cleanup)
    @i1.go
  end
  
  it "should pop all the arguments" do
    @context.clear_stacks
    5.times {@context.stacks[:int].push(@int1)}
    @i1.stub!(:cleanup) # and do nothing
    @i1.go
    @context.stacks[:int].depth.should == 3
  end
  
  it "should push the result" do
    @context.clear_stacks
    @context.stacks[:int].push(@int1)
    @context.stacks[:int].push(@int1)
    @i1.go
    @context.stacks[:bool].peek.value.should == false
    
    @context.stacks[:int].push(@int1)
    @context.stacks[:int].push(@int2)
    @i1.go
    @context.stacks[:bool].peek.value.should == true
    
    @context.stacks[:int].push(@int2)
    @context.stacks[:int].push(@int1)
    @i1.go
    @context.stacks[:bool].peek.value.should == false
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

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