Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changing Number to include all of the Math functions
- Loading branch information
1 parent
735bf54
commit 5a52a5a
Showing
4 changed files
with
96 additions
and
58 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,25 +1,97 @@ | ||
describe('Number', function() { | ||
describe('#abs', function() { | ||
it('returns the absolute value of a number', function() { | ||
expect((-1).abs()).toEqual(1); | ||
it('returns the abs of a number', function() { | ||
expect((-1).abs()).toEqual(Math.abs(-1)); | ||
}); | ||
}); | ||
|
||
describe('#acos', function() { | ||
it('returns the acos of a number', function() { | ||
expect((-1).acos()).toEqual(Math.acos(-1)); | ||
}); | ||
}); | ||
|
||
describe('#asin', function() { | ||
it('returns the asin of a number', function() { | ||
expect((-1).asin()).toEqual(Math.asin(-1)); | ||
}); | ||
}); | ||
|
||
describe('#atan', function() { | ||
it('returns the atan of a number', function() { | ||
expect((1).atan()).toEqual(Math.atan(1)); | ||
}); | ||
}); | ||
|
||
describe('#atan2', function() { | ||
it('returns the atan2 of a number', function() { | ||
expect((4).atan2(8)).toEqual(Math.atan2(4, 8)); | ||
}); | ||
}); | ||
|
||
describe('#ceil', function() { | ||
it('returns the smallest integer greater than or equal to the number', function() { | ||
expect((0.1).ceil()).toEqual(1); | ||
it('returns the ceil of a number', function() { | ||
expect((0.1).ceil()).toEqual(Math.ceil(0.1)); | ||
}); | ||
}); | ||
|
||
describe('#exp', function() { | ||
it('returns the exp of a number', function() { | ||
expect((5).exp()).toEqual(Math.exp(5)); | ||
}); | ||
}); | ||
|
||
describe('#floor', function() { | ||
it('returns the largest integer less than or equal to the number.r', function() { | ||
expect((1.9).floor()).toEqual(1); | ||
it('returns the floor of a number', function() { | ||
expect((1.9).floor()).toEqual(Math.floor(1.9)); | ||
}); | ||
}); | ||
|
||
describe('#log', function() { | ||
it('returns the log of a number', function() { | ||
expect((5).log()).toEqual(Math.log(5)); | ||
}); | ||
}); | ||
|
||
describe('#max', function() { | ||
it('returns the max of a number', function() { | ||
expect((25).max(10, 15, 0)).toEqual(Math.max(25, 10, 15, 0)); | ||
}); | ||
}); | ||
|
||
describe('#min', function() { | ||
it('returns the min of a number', function() { | ||
expect((5).min(10, 15)).toEqual(Math.min(5, 10, 15)); | ||
}); | ||
}); | ||
|
||
describe('#pow', function() { | ||
it('returns the pow of a number', function() { | ||
expect((5).pow(2)).toEqual(Math.pow(5, 2)); | ||
}); | ||
}); | ||
|
||
describe('#round', function() { | ||
it('rounds the number to the nearest integer', function() { | ||
expect((0.8).round()).toEqual(1); | ||
expect((0.8).round()).toEqual(Math.round(0.8)); | ||
}); | ||
}); | ||
|
||
describe('#sin', function() { | ||
it('returns the sin of a number', function() { | ||
expect((1).sin()).toEqual(Math.sin(1)); | ||
}); | ||
}); | ||
|
||
describe('#sqrt', function() { | ||
it('returns the sqrt of a number', function() { | ||
expect((9).sqrt()).toEqual(Math.sqrt(9)); | ||
}); | ||
}); | ||
|
||
describe('#tan', function() { | ||
it('returns the tan of a number', function() { | ||
expect((1).tan()).toEqual(Math.tan(1)); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,27 +1,10 @@ | ||
classify(Number, function() { | ||
// Returns the absolute value of the number. Convenience method that simply | ||
// calls `Math.abs` on this instance and returns the result. | ||
def('abs', function() { | ||
return Math.abs(this); | ||
}); | ||
|
||
// Rounds the number to the nearest integer. Convenience method that simply | ||
// calls `Math.round` on this instance and returns the result. | ||
def('round', function() { | ||
return Math.round(this); | ||
}); | ||
|
||
// Returns the smallest integer greater than or equal to the number. | ||
// Convenience method that simply calls `Math.ceil` on this instance and | ||
// returns the result. | ||
def('ceil', function() { | ||
return Math.ceil(this); | ||
}); | ||
|
||
// Returns the largest integer less than or equal to the number. | ||
// Convenience method that simply calls `Math.floor` on this instance and | ||
// returns the result. | ||
def('floor', function() { | ||
return Math.floor(this); | ||
}); | ||
// Copy over each Math method into the Number prototype. | ||
(function(math) { | ||
math.each(function(name) { | ||
def(name, function() { | ||
return Math[name].apply(null, [ this ].concat(slice.call(arguments))); | ||
}); | ||
}); | ||
})([ 'abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'round', 'sin', 'sqrt', 'tan' ]); | ||
}); |