-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shared spec integer_ceil_precision
This spec can be shared between Integer#ceil and Float#ceil and improves coverage of cases where precision is passed in.
- Loading branch information
1 parent
59d3c7e
commit f78487f
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
describe :integer_ceil_precision, shared: true do | ||
context "precision is zero" do | ||
it "returns integer self" do | ||
send(@method, 0).ceil(0).should.eql?(0) | ||
send(@method, 123).ceil(0).should.eql?(123) | ||
send(@method, -123).ceil(0).should.eql?(-123) | ||
end | ||
end | ||
|
||
context "precision is positive" do | ||
it "returns self" do | ||
send(@method, 0).ceil(1).should.eql?(send(@method, 0)) | ||
send(@method, 0).ceil(10).should.eql?(send(@method, 0)) | ||
|
||
send(@method, 123).ceil(10).should.eql?(send(@method, 123)) | ||
send(@method, -123).ceil(10).should.eql?(send(@method, -123)) | ||
end | ||
end | ||
|
||
context "precision is negative" do | ||
it "always returns 0 when self is 0" do | ||
send(@method, 0).ceil(-1).should.eql?(0) | ||
send(@method, 0).ceil(-10).should.eql?(0) | ||
end | ||
|
||
it "returns largest integer less than self with at least precision.abs trailing zeros" do | ||
send(@method, 123).ceil(-1).should.eql?(130) | ||
send(@method, 123).ceil(-2).should.eql?(200) | ||
send(@method, 123).ceil(-3).should.eql?(1000) | ||
|
||
send(@method, -123).ceil(-1).should.eql?(-120) | ||
send(@method, -123).ceil(-2).should.eql?(-100) | ||
send(@method, -123).ceil(-3).should.eql?(0) | ||
end | ||
end | ||
end |