File: none_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 (48 lines) | stat: -rw-r--r-- 1,263 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
36
37
38
39
40
41
42
43
44
45
46
47
48
require "spec_helper"
require "hamster/set"

describe Hamster::Set do
  describe "#none?" do
    context "when empty" do
      it "with a block returns true" do
        S.empty.none? {}.should == true
      end

      it "with no block returns true" do
        S.empty.none?.should == true
      end
    end

    context "when not empty" do
      context "with a block" do
        let(:set) { S["A", "B", "C", nil] }

        ["A", "B", "C", nil].each do |value|
          it "returns false if the block ever returns true (#{value.inspect})" do
            set.none? { |item| item == value }.should == false
          end
        end

        it "returns true if the block always returns false" do
          set.none? { |item| item == "D" }.should == true
        end

        it "stops iterating as soon as the block returns true" do
          yielded = []
          set.none? { |item| yielded << item; true }
          yielded.size.should == 1
        end
      end

      context "with no block" do
        it "returns false if any value is truthy" do
          S[nil, false, true, "A"].none?.should == false
        end

        it "returns true if all values are falsey" do
          S[nil, false].none?.should == true
        end
      end
    end
  end
end