Sha256: 238d679cd85c07d1e5ee927974b743271bbb8b1ae41ff4bd0fe978e174322cea

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

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

describe SPNet::SignalInPort do
  describe '.new' do
    it 'should have an empty queue' do
      port = SPNet::SignalInPort.new
      port.queue.should be_empty
    end
  end

  describe '#enqueue_values' do
    it 'should add values to queue' do
      port = SPNet::SignalInPort.new
      values = [2.4, 2.6, 4.9, 5.1]
      
      port.enqueue_values(values.clone)
      values.should eq(port.queue)
    end
  
    it 'should limit all values before queuing them' do
      limiter = RangeLimiter.new(2.5, true, 5.0, true)
      port = SPNet::SignalInPort.new(:limiter => limiter)
      port.enqueue_values([2.4, 2.6, 4.9, 5.1])
      port.queue.each do |value|
        value.should be_between(2.5, 5.0)
      end
    end
  end

  describe '#dequeue_values' do
    it 'should remove N values from queue' do
      port = SPNet::SignalInPort.new
      values = [2.4, 2.6, 4.9, 5.1]
      port.enqueue_values(values.clone)
      values2 = port.dequeue_values 2
      port.queue.count.should be 2
      values2.count.should be 2
      values2.first.should eq(values.first)
    end    
    
    it 'should remove all values from queue if no count is given' do
      port = SPNet::SignalInPort.new
      values = [2.4, 2.6, 4.9, 5.1]
      port.enqueue_values(values.clone)
      values2 = port.dequeue_values
      port.queue.should be_empty
      values2.should eq(values)
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spnet-0.1.8 spec/ports/signal_in_port_spec.rb
spnet-0.1.7 spec/ports/signal_in_port_spec.rb