Skip to content

Commit d439436

Browse files
committed
Merge pull request #160 from JuanitoFatas/ruby-23/core/hash-comparison
[Core/hash] Add specs for Hash #<=, #>=, #<, #> for Ruby 2.3
2 parents 1a1fcb6 + 7f3b584 commit d439436

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

core/hash/gt_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require File.expand_path('../../../spec_helper', __FILE__)
2+
3+
ruby_version_is "2.3" do
4+
describe "Hash#>" do
5+
before :each do
6+
@hash = {a:1, b:2}
7+
@bigger = {a:1, b:2, c:3}
8+
@unrelated = {c:3, d:4}
9+
@similar = {a:2, b:3}
10+
end
11+
12+
it "returns false when receiver size is smaller than argument" do
13+
(@hash > @bigger).should == false
14+
(@unrelated > @bigger).should == false
15+
end
16+
17+
it "returns false when receiver size is the same as argument" do
18+
(@hash > @hash).should == false
19+
(@hash > @unrelated).should == false
20+
(@unrelated > @hash).should == false
21+
end
22+
23+
it "returns true when argument is a subset of receiver" do
24+
(@bigger > @hash).should == true
25+
end
26+
27+
it "returns false when keys match but values don't" do
28+
(@hash > @similar).should == false
29+
(@similar > @hash).should == false
30+
end
31+
end
32+
end

core/hash/gte_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require File.expand_path('../../../spec_helper', __FILE__)
2+
3+
ruby_version_is "2.3" do
4+
describe "Hash#>=" do
5+
before :each do
6+
@hash = {a:1, b:2}
7+
@bigger = {a:1, b:2, c:3}
8+
@unrelated = {c:3, d:4}
9+
@similar = {a:2, b:3}
10+
end
11+
12+
it "returns false when receiver size is smaller than argument" do
13+
(@hash >= @bigger).should == false
14+
(@unrelated >= @bigger).should == false
15+
end
16+
17+
it "returns false when argument is not a subset or not equals to receiver" do
18+
(@hash >= @unrelated).should == false
19+
(@unrelated >= @hash).should == false
20+
end
21+
22+
it "returns true when argument is a subset of receiver or equals to receiver" do
23+
(@bigger >= @hash).should == true
24+
(@hash >= @hash).should == true
25+
end
26+
27+
it "returns false when keys match but values don't" do
28+
(@hash >= @similar).should == false
29+
(@similar >= @hash).should == false
30+
end
31+
end
32+
end

core/hash/lt_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require File.expand_path('../../../spec_helper', __FILE__)
2+
3+
ruby_version_is "2.3" do
4+
describe "Hash#<" do
5+
before :each do
6+
@hash = {a:1, b:2}
7+
@bigger = {a:1, b:2, c:3}
8+
@unrelated = {c:3, d:4}
9+
@similar = {a:2, b:3}
10+
end
11+
12+
it "returns false when receiver size is larger than argument" do
13+
(@bigger < @hash).should == false
14+
(@bigger < @unrelated).should == false
15+
end
16+
17+
it "returns false when receiver size is the same as argument" do
18+
(@hash < @hash).should == false
19+
(@hash < @unrelated).should == false
20+
(@unrelated < @hash).should == false
21+
end
22+
23+
it "returns true when receiver is a subset of argument" do
24+
(@hash < @bigger).should == true
25+
end
26+
27+
it "returns false when keys match but values don't" do
28+
(@hash < @similar).should == false
29+
(@similar < @hash).should == false
30+
end
31+
end
32+
end

core/hash/lte_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require File.expand_path('../../../spec_helper', __FILE__)
2+
3+
ruby_version_is "2.3" do
4+
describe "Hash#<=" do
5+
before :each do
6+
@hash = {a:1, b:2}
7+
@bigger = {a:1, b:2, c:3}
8+
@unrelated = {c:3, d:4}
9+
@similar = {a:2, b:3}
10+
end
11+
12+
it "returns false when receiver size is larger than argument" do
13+
(@bigger <= @hash).should == false
14+
(@bigger <= @unrelated).should == false
15+
end
16+
17+
it "returns false when receiver size is the same as argument" do
18+
(@hash <= @unrelated).should == false
19+
(@unrelated <= @hash).should == false
20+
end
21+
22+
it "returns true when receiver is a subset of argument or equals to argument" do
23+
(@hash <= @bigger).should == true
24+
(@hash <= @hash).should == true
25+
end
26+
27+
it "returns false when keys match but values don't" do
28+
(@hash <= @similar).should == false
29+
(@similar <= @hash).should == false
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)