File: random_modification_spec.rb

package info (click to toggle)
ruby-hamster 3.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,932 kB
  • sloc: ruby: 16,915; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 910 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "spec_helper"
require "hamster/deque"

describe Hamster::Deque do
  describe "modification (using #push, #pop, #shift, and #unshift)" do
    it "works when applied in many random combinations" do
      array = [1,2,3]
      deque = Hamster::Deque.new(array)
      1000.times do
        case [:push, :pop, :shift, :unshift].sample
        when :push
          value = rand(10000)
          array.push(value)
          deque = deque.push(value)
        when :pop
          array.pop
          deque = deque.pop
        when :shift
          array.shift
          deque = deque.shift
        when :unshift
          value = rand(10000)
          array.unshift(value)
          deque = deque.unshift(value)
        end

        deque.to_a.should eql(array)
        deque.size.should == array.size
        deque.first.should == array.first
        deque.last.should == array.last
      end
    end
  end
end