Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bozhidar Batsov
committed
Aug 21, 2013
1 parent
c99a733
commit c50e367
Showing
7 changed files
with
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
|
||
require 'powerpack/hash' | ||
|
||
require 'powerpack/numeric' | ||
|
||
require 'powerpack/string' |
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,2 @@ | ||
require_relative 'numeric/neg' | ||
require_relative 'numeric/pos' |
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,19 @@ | ||
unless Numeric.method_defined? :neg? | ||
class Numeric | ||
# Checks whether a number is negative. | ||
# | ||
# @return [Boolean] true is the number is negative, false otherwise | ||
# | ||
# @example | ||
# 5.neg? #=> false | ||
# | ||
# @example | ||
# -0.5.neg? #=> true | ||
# | ||
# @example | ||
# 0.neg? #=> false | ||
def neg? | ||
self < 0 | ||
end | ||
end | ||
end |
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,19 @@ | ||
unless Numeric.method_defined? :pos? | ||
class Numeric | ||
# Checks whether a number is positive. | ||
# | ||
# @return [Boolean] true is the number is positive, false otherwise | ||
# | ||
# @example | ||
# 5.pos? #=> true | ||
# | ||
# @example | ||
# -0.5.pos? #=> false | ||
# | ||
# @example | ||
# 0.pos? #=> false | ||
def pos? | ||
self > 0 | ||
end | ||
end | ||
end |
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,24 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Numeric#neg?' do | ||
it 'returns false for positive integer' do | ||
expect(1.neg?).to be_false | ||
end | ||
|
||
it 'returns false for positive float' do | ||
expect(0.1.neg?).to be_false | ||
end | ||
|
||
it 'returns true for negative integer' do | ||
expect(-1.neg?).to be_true | ||
end | ||
|
||
it 'returns true for negative float' do | ||
expect(-0.01.neg?).to be_true | ||
end | ||
|
||
it 'returns false for 0' do | ||
expect(0.neg?).to be_false | ||
expect(0.0.neg?).to be_false | ||
end | ||
end |
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,24 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Numeric#pos?' do | ||
it 'returns true for positive integer' do | ||
expect(1.pos?).to be_true | ||
end | ||
|
||
it 'returns true for positive float' do | ||
expect(0.1.pos?).to be_true | ||
end | ||
|
||
it 'returns false for negative integer' do | ||
expect(-1.pos?).to be_false | ||
end | ||
|
||
it 'returns false for negative float' do | ||
expect(-0.01.pos?).to be_false | ||
end | ||
|
||
it 'returns false for 0' do | ||
expect(0.pos?).to be_false | ||
expect(0.0.pos?).to be_false | ||
end | ||
end |