File: drop_while_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 (35 lines) | stat: -rw-r--r-- 961 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
35
require "spec_helper"
require "hamster/sorted_set"

describe Hamster::SortedSet do
  describe "#drop_while" do
    [
      [[], []],
      [["A"], []],
      [%w[A B C], ["C"]],
      [%w[A B C D E F G], %w[C D E F G]]
    ].each do |values, expected|
      context "on #{values.inspect}" do
        let(:sorted_set) { SS[*values] }

        context "with a block" do
          it "preserves the original" do
            sorted_set.drop_while { |item| item < "C" }
            sorted_set.should eql(SS[*values])
          end

          it "returns #{expected.inspect}" do
            sorted_set.drop_while { |item| item < "C" }.should eql(SS[*expected])
          end
        end

        context "without a block" do
          it "returns an Enumerator" do
            sorted_set.drop_while.class.should be(Enumerator)
            sorted_set.drop_while.each { |item| item < "C" }.should eql(SS[*expected])
          end
        end
      end
    end
  end
end