diff options
| author | Luc Donnet | 2018-02-19 11:04:29 +0100 | 
|---|---|---|
| committer | Luc Donnet | 2018-02-19 11:04:29 +0100 | 
| commit | 7b17deff51545358009cb417cbb9d796565e7540 (patch) | |
| tree | a43a5586ad39d838dd607e600dbc15ff18a58ab3 /spec/lib/range_ext_spec.rb | |
| parent | 89428163fc93a7e09ebb0ca47939f8558afeb5eb (diff) | |
| parent | 5f6008d165df4499319a2121a71842657d6ac3c9 (diff) | |
| download | chouette-core-7b17deff51545358009cb417cbb9d796565e7540.tar.bz2 | |
Merge branch 'master' into 0000-docker
Diffstat (limited to 'spec/lib/range_ext_spec.rb')
| -rw-r--r-- | spec/lib/range_ext_spec.rb | 51 | 
1 files changed, 50 insertions, 1 deletions
| diff --git a/spec/lib/range_ext_spec.rb b/spec/lib/range_ext_spec.rb index 9c44608b9..eee488c91 100644 --- a/spec/lib/range_ext_spec.rb +++ b/spec/lib/range_ext_spec.rb @@ -1,6 +1,6 @@  require 'range_ext'  RSpec.describe Range do -  context "intersection" do +  describe "#intersection" do      it "is nil (sic) for two distinct ranges" do        expect( (1..2).intersection(3..4) ).to be_nil      end @@ -15,4 +15,53 @@ RSpec.describe Range do        expect( (2..4) & (1..3) ).to eq 2..3      end    end + +  describe "intersect?" do +    it 'is true when the given range includes begin' do +      expect( (2..4).intersect? (1..3) ).to be_truthy +    end + +    it 'is true when the given range includes end' do +      expect( (2..4).intersect? (3..5) ).to be_truthy +    end + +    it 'is true when the given range includes both begin and end' do +      expect( (2..4).intersect? (1..5) ).to be_truthy +    end + +    it 'is true when the given range is the same' do +      expect( (2..4).intersect? (2..4) ).to be_truthy +    end + +    it 'is false when the given range is after' do +      expect( (2..4).intersect? (5..7) ).to be_falsey +    end + +    it 'is false when the given range is before' do +      expect( (2..4).intersect? (0..2) ).to be_falsey +    end +  end + +  context "remove" do +    it "is unchanged when the given range has no intersection" do +      expect( (1..2).remove(3..4) ).to eq 1..2 +      expect( (3..4).remove(1..2) ).to eq 3..4 +    end + +    it "is nil for two equal ranges" do +      expect( (1..2).remove(1..2) ).to be_empty +    end + +    it "is the begin of the range when given range intersect the end" do +      expect( (5..10).remove(8..15) ).to eq [5..7] +    end + +    it "is the end of the range when given range intersect the begin" do +      expect( (5..10).remove(1..6) ).to eq [7..10] +    end + +    it "is the two remaing ranges when given range is the middle" do +      expect( (1..10).remove(4..6) ).to eq [1..3, 7..10] +    end +  end  end | 
