Created
January 3, 2018 06:09
-
-
Save hanmd82/c35d79cb7fc8e640b035daf040d944a8 to your computer and use it in GitHub Desktop.
ES6 katas for Numbers - http://es6katas.org/
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
// 55: Number - isInteger | |
describe('`Number.isInteger()` determines if a value is an integer', function(){ | |
const isTrue = (what) => assert.equal(what, true); | |
const isFalse = (what) => assert.equal(what, false); | |
it('`isInteger` is a static function on `Number`', function() { | |
const whatType = 'function'; | |
assert.equal(typeof Number.isInteger, whatType); | |
}); | |
describe('zero in different ways', function() { | |
it('0 is an integer', function() { | |
const zero = 0; | |
isTrue(Number.isInteger(zero)); | |
}); | |
it('0.000', function() { | |
isTrue(Number.isInteger(0.000)); | |
}); | |
it('the string "0" is NOT an integer', function() { | |
const stringZero = '0'; | |
isFalse(Number.isInteger(stringZero)); | |
}); | |
}); | |
describe('one in different ways', function() { | |
it('0.111 + 0.889', function() { | |
const rest = 0.889; | |
isTrue(Number.isInteger(0.111 + rest)); | |
}); | |
it('0.5 + 0.2 + 0.2 + 0.1 = 1 ... isn`t it?', function() { | |
const oneOrNot = 0.5 + 0.2 + 0.2 + 0.1; | |
isFalse(Number.isInteger(oneOrNot)); | |
}); | |
it('parseInt`ed "1" is an integer', function() { | |
const convertedToInt = Number.parseInt('1.01'); | |
isTrue(Number.isInteger(convertedToInt)); | |
}); | |
}); | |
describe('what is not an integer', function() { | |
it('`Number()` is an integer', function() { | |
const numberOne = Number(); | |
isTrue(Number.isInteger(numberOne)); | |
}); | |
it('`{}` is NOT an integer', function() { | |
const isit = Number.isInteger({}); | |
isFalse(isit); | |
}); | |
it('`0.1` is not an integer', function() { | |
const isit = Number.isInteger(0.1); | |
isFalse(isit); | |
}); | |
it('`Number.Infinity` is not an integer', function() { | |
const isit = Number.isInteger(Number.Infinity); | |
isFalse(isit); | |
}); | |
it('`NaN` is not an integer', function() { | |
const isit = Number.isInteger(NaN); | |
isFalse(isit); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment