-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
11 changed files
with
178 additions
and
43 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,5 @@ | ||
'use strict'; | ||
|
||
const sumOf = values => values.reduce((sum, size) => sum + size, 0); | ||
|
||
module.exports = { sumOf }; |
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
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 isOfType = (operand, type) => typeof operand === type; | ||
const isBoolean = value => typeof value === 'boolean'; | ||
const isObject = value => typeof value === 'object'; | ||
const isString = value => typeof value === 'string'; | ||
const isUndefined = value => typeof value === 'undefined'; | ||
const isInteger = value => Number.isInteger(value) && Number.isFinite(value) && `${value}`; | ||
const isArray = value => Array.isArray(value); | ||
const isEmptyArray = value => isArray(value) && value.length === 0; | ||
|
||
module.exports = { | ||
isOfType, | ||
isUndefined, | ||
isInteger, | ||
isArray, | ||
isBoolean, | ||
isString, | ||
isObject, | ||
isEmptyArray | ||
}; |
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
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,7 @@ | ||
'use strict'; | ||
|
||
const { sumOf } = require('../../../../app/functional'); | ||
|
||
test('Should be able to sum up', () => { | ||
expect(sumOf([1, 2, 3])).toBe(6); | ||
}); |
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,101 @@ | ||
'use strict'; | ||
|
||
const { | ||
isOfType, | ||
isUndefined, | ||
isInteger, | ||
isArray, | ||
isBoolean, | ||
isString, | ||
isObject, | ||
isEmptyArray | ||
} = require('../../../../app/validator/validator.js'); | ||
|
||
test('Should be able to check the type of the operand', () => { | ||
const foo = { bar: 'foobar' }; | ||
expect(isOfType('hello', 'string')).toBeTruthy(); | ||
expect(isOfType(123, 'number')).toBeTruthy(); | ||
expect(isOfType(foo.bar, 'string')).toBeTruthy(); | ||
|
||
expect(isOfType('123', 'number')).toBeFalsy(); | ||
expect(isOfType(foo.unknown, 'string')).toBeFalsy(); | ||
}); | ||
|
||
test('Should be able to determine that an value is undefined', () => { | ||
const foo = { bar: 'foobar' }; | ||
expect(isUndefined(foo.bar)).toBeFalsy(); | ||
expect(isUndefined(foo.unknown)).toBeTruthy(); | ||
}); | ||
|
||
test('Should be able to determine that value is integer', () => { | ||
const foo = { bar: 123 }; | ||
expect(isInteger(0)).toBeTruthy(); | ||
expect(isInteger(123)).toBeTruthy(); | ||
expect(isInteger(1e14)).toBeTruthy(); | ||
expect(isInteger(-1e14)).toBeTruthy(); | ||
expect(isInteger(foo.bar)).toBeTruthy(); | ||
|
||
expect(isInteger('123')).toBeFalsy(); | ||
expect(isInteger('123.0')).toBeFalsy(); | ||
expect(isInteger(12.3)).toBeFalsy(); | ||
expect(isInteger(Number.POSITIVE_INFINITY)).toBeFalsy(); | ||
expect(isInteger(Number.NEGATIVE_INFINITY)).toBeFalsy(); | ||
expect(isInteger(foo.unknown)).toBeFalsy(); | ||
}); | ||
|
||
test('Should be able to determine that value is an array', () => { | ||
expect(isArray([])).toBeTruthy(); | ||
expect(isArray(['a'])).toBeTruthy(); | ||
expect(isArray([1])).toBeTruthy(); | ||
|
||
expect(isArray(1)).toBeFalsy(); | ||
expect(isArray('1')).toBeFalsy(); | ||
expect(isArray({})).toBeFalsy(); | ||
expect(isArray(null)).toBeFalsy(); | ||
expect(isArray(undefined)).toBeFalsy(); | ||
}); | ||
|
||
test('Should be able to determine that value is boolean', () => { | ||
expect(isBoolean(true)).toBeTruthy(); | ||
expect(isBoolean(false)).toBeTruthy(); | ||
|
||
expect(isBoolean('true')).toBeFalsy(); | ||
expect(isBoolean('false')).toBeFalsy(); | ||
expect(isBoolean(1)).toBeFalsy(); | ||
expect(isBoolean(0)).toBeFalsy(); | ||
expect(isBoolean({})).toBeFalsy(); | ||
expect(isBoolean([])).toBeFalsy(); | ||
expect(isBoolean(null)).toBeFalsy(); | ||
expect(isBoolean(undefined)).toBeFalsy(); | ||
}); | ||
|
||
test('Should be able to determine that value is string', () => { | ||
expect(isString('')).toBeTruthy(); | ||
expect(isString('hello')).toBeTruthy(); | ||
|
||
expect(isString(true)).toBeFalsy(); | ||
expect(isString(false)).toBeFalsy(); | ||
expect(isString(1)).toBeFalsy(); | ||
expect(isString(0)).toBeFalsy(); | ||
expect(isString({})).toBeFalsy(); | ||
expect(isString([])).toBeFalsy(); | ||
expect(isString(null)).toBeFalsy(); | ||
expect(isString(undefined)).toBeFalsy(); | ||
}); | ||
|
||
test('Should be able to determine that value is an empty array', () => { | ||
expect(isEmptyArray([])).toBeTruthy(); | ||
|
||
expect(isEmptyArray([1])).toBeFalsy(); | ||
}); | ||
|
||
test('Should be able to determine that value is object', () => { | ||
expect(isObject({})).toBeTruthy(); | ||
expect(isObject({ foo: 'bar' })).toBeTruthy(); | ||
|
||
expect(isObject(true)).toBeFalsy(); | ||
expect(isObject(false)).toBeFalsy(); | ||
expect(isObject(1)).toBeFalsy(); | ||
expect(isObject(0)).toBeFalsy(); | ||
expect(isObject(undefined)).toBeFalsy(); | ||
}); |