Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs for Set#<=> method #866

Merged
merged 2 commits into from
Oct 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions library/set/comparison_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require_relative '../../spec_helper'
require 'set'

ruby_version_is "3.0" do
describe "Set#<=>" do
it "returns 0 if the sets are equal" do
(Set[] <=> Set[]).should == 0
(Set[:a, :b, :c] <=> Set[:a, :b, :c]).should == 0
end

it "returns -1 if the set is a proper subset of the other set" do
(Set[] <=> Set[1]).should == -1
(Set[1, 2] <=> Set[1, 2, 3]).should == -1
end

it "returns +1 if the set is a proper superset of other set" do
(Set[1] <=> Set[]).should == +1
(Set[1, 2, 3] <=> Set[1, 2]).should == +1
end

it "returns nil if the set has unique elements" do
(Set[1, 2, 3] <=> Set[:a, :b, :c]).should be_nil
end

it "returns nil when the argument is not set-like" do
(Set[] <=> false).should be_nil
end
end
end