-
-
Save waaa/1952009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rspec' | |
def includes arg1, arg2 | |
arg1 = arg1.split if arg1.is_a? String | |
arg2 = arg2.split if arg2.is_a? String | |
not (arg1 & arg2).empty? | |
end | |
def includes_only arg1, arg2 | |
arg1 = arg1.split if arg1.is_a? String | |
arg2 = arg2.split if arg2.is_a? String | |
(arg1 - arg2).empty? | |
end | |
describe "#includes" do | |
it "should be true for equal lists" do | |
includes( ['SVO'], ['SVO'] ).should == true | |
end | |
specify { includes( ['SVO', 'CDG'], ['DME', 'SVO'] ).should == true } | |
specify { includes( ['SVO', 'CDG'], ['DME'] ).should == false } | |
specify { includes( 'SVO', 'SVO' ).should == true } | |
specify { includes( 'SVO CDG', 'SVO' ).should == true } | |
specify { includes( 'SVO CDG', 'DME SVO' ).should == true } | |
end | |
describe "#includes_only" do | |
it "should be true for equal lists" do | |
includes_only( ['SVO'], ['SVO'] ).should == true | |
end | |
it "should be true when first set is a subset of second set" do | |
includes_only( ['SVO'], ['SVO', 'DME'] ).should == true | |
end | |
it "should be false when second set is only a partial subset of first set" do | |
includes_only( ['SVO', 'DME'], ['SVO'] ).should == false | |
end | |
specify { includes_only( ['SVO', 'CDG'], ['DME', 'SVO'] ).should == false } | |
specify { includes_only( ['SVO', 'CDG', 'SVO'], ['CDG', 'SVO'] ).should == true } | |
specify { includes_only( ['SVO', 'CDG'], ['DME'] ).should == false } | |
specify { includes_only( 'SVO', 'SVO' ).should == true } | |
specify { includes_only( 'SVO CDG SVO', 'SVO CDG' ).should == true } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment