-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base foundation() created, flexRange() created, basic test written
- Loading branch information
Showing
6 changed files
with
94 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "stable" | ||
branches: | ||
only: | ||
- master |
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,11 +1,6 @@ | ||
'use strict'; | ||
|
||
const Purify = require('purify-int') | ||
const Crypto = require('crypto') | ||
const dep = require('./deprecated/v1') // floor(), ceil() | ||
const libs = require('./libs') // range() | ||
|
||
const { floor, ceil } = require('./deprecated/v1') | ||
|
||
module.exports = { | ||
floor, | ||
ceil | ||
} | ||
module.exports = Object.assign({}, dep, libs) |
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,21 @@ | ||
'use strict' | ||
|
||
const Purify = require('purify-int') | ||
const Crypto = require('crypto') | ||
|
||
// INTERNAL | ||
function foundation(base) { | ||
const pureBase = Math.abs(base) | ||
const byteCount = Math.ceil(pureBase / 256) | ||
const hexString = Crypto.randomBytes(byteCount).toString('hex') | ||
return parseInt(hexString, 16) % pureBase | ||
} | ||
|
||
// EXTERNAL | ||
function flexRange(v) { | ||
const pureV = Purify.asInt(v) | ||
const result = foundation(pureV) | ||
return (pureV < 0) ? result * -1 : result | ||
} | ||
|
||
module.exports = { flexRange } |
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,46 @@ | ||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const { ceil, floor } = require('../../deprecated/v1'); | ||
|
||
describe('makeRandom ceil()', () => { | ||
it(`should have the method 'ceil'`, ()=> { | ||
expect(ceil).to.be.a('function'); | ||
}); | ||
it(`should return a number`, () => { | ||
expect(ceil(10)).to.be.a('number'); | ||
expect(ceil('10')).to.be.an('number'); | ||
}); | ||
it(`should not return a negative zero`, () => { | ||
expect(ceil(-0)).to.equal(0); | ||
}); | ||
|
||
it(`should return 0 if a number or number string is not passed to ceil()`, () => { | ||
expect(ceil('test')).to.equal(0); | ||
expect(ceil(true)).to.equal(0); | ||
expect(ceil({})).to.equal(0); | ||
expect(ceil([])).to.equal(0); | ||
expect(ceil(() => {})).to.equal(0); | ||
}); | ||
}); | ||
|
||
describe('makeRandom floor()', () => { | ||
it(`should have the method 'floor'`, ()=> { | ||
expect(floor).to.be.a('function'); | ||
}); | ||
it(`should return a number`, () => { | ||
expect(floor(10)).to.be.a('number'); | ||
expect(floor('10')).to.be.an('number'); | ||
}); | ||
it(`should not return a negative zero`, () => { | ||
expect(floor(-0)).to.equal(0); | ||
}); | ||
it(`should return 0 if a number or number string is not passed to ceil()`, () => { | ||
expect(floor('test')).to.equal(0); | ||
expect(floor(true)).to.equal(0); | ||
expect(floor({})).to.equal(0); | ||
expect(floor([])).to.equal(0); | ||
expect(floor(() => {})).to.equal(0); | ||
}); | ||
}); |
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,46 +1,25 @@ | ||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const { ceil, floor } = require('../../index'); | ||
const expect = require('chai').expect; | ||
const { fixedRange, flexRange } = require('../../libs'); | ||
|
||
describe('makeRandom ceil()', () => { | ||
it(`should have the method 'ceil'`, ()=> { | ||
expect(ceil).to.be.a('function'); | ||
}); | ||
it(`should return a number`, () => { | ||
expect(ceil(10)).to.be.a('number'); | ||
expect(ceil('10')).to.be.an('number'); | ||
}); | ||
it(`should not return a negative zero`, () => { | ||
expect(ceil(-0)).to.equal(0); | ||
}); | ||
|
||
it(`should return 0 if a number or number string is not passed to ceil()`, () => { | ||
expect(ceil('test')).to.equal(0); | ||
expect(ceil(true)).to.equal(0); | ||
expect(ceil({})).to.equal(0); | ||
expect(ceil([])).to.equal(0); | ||
expect(ceil(() => {})).to.equal(0); | ||
}); | ||
}); | ||
|
||
describe('makeRandom floor()', () => { | ||
it(`should have the method 'floor'`, ()=> { | ||
expect(floor).to.be.a('function'); | ||
}); | ||
it(`should return a number`, () => { | ||
expect(floor(10)).to.be.a('number'); | ||
expect(floor('10')).to.be.an('number'); | ||
}); | ||
it(`should not return a negative zero`, () => { | ||
expect(floor(-0)).to.equal(0); | ||
}); | ||
it(`should return 0 if a number or number string is not passed to ceil()`, () => { | ||
expect(floor('test')).to.equal(0); | ||
expect(floor(true)).to.equal(0); | ||
expect(floor({})).to.equal(0); | ||
expect(floor([])).to.equal(0); | ||
expect(floor(() => {})).to.equal(0); | ||
describe('makeRandom flexRange()', () => { | ||
it(`should have the method 'flexRange'`, ()=> { | ||
expect(flexRange).to.be.a('function'); | ||
}); | ||
it(`should return a positive random number`, () => { | ||
expect(flexRange(10)).to.be.a('number').and.be.greaterThan(-1); | ||
expect(flexRange('10')).to.be.an('number').and.be.greaterThan(-1); | ||
}); | ||
it(`should return a negative random number`, () => { | ||
expect(flexRange(-10)).to.be.a('number').and.be.lessThan(0); | ||
expect(flexRange('-10')).to.be.an('number').and.be.lessThan(0); | ||
}); | ||
// it(`should return 0 if a number or number string is not passed to range()`, () => { | ||
// expect(flexRange('test')).to.equal(0); | ||
// expect(flexRange(true)).to.equal(0); | ||
// expect(flexRange({})).to.equal(0); | ||
// expect(flexRange([])).to.equal(0); | ||
// expect(flexRange(() => {})).to.equal(0); | ||
// }); | ||
}); |