Skip to content

Commit

Permalink
feat(numeric): adding numericGreaterThan condition operator
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Feb 25, 2021
1 parent 7ceb06d commit 01384d0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/conditionOperators/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {numericEquals} from './numeric/numericEquals';
import {numericGreaterThan} from './numeric/numericGreaterThan';
import {numericLessThan} from './numeric/numericLessThan';
import {numericLessThanEquals} from './numeric/numericLessThanEquals';
import {numericNotEquals} from './numeric/numericNotEquals';
Expand All @@ -10,6 +11,7 @@ import {stringNotEqualsIgnoreCase} from './string/stringNotEqualsIgnoreCase';

export const operators: Record<string, unknown>={
numericEquals,
numericGreaterThan,
numericLessThan,
numericLessThanEquals,
numericNotEquals,
Expand Down
15 changes: 15 additions & 0 deletions src/conditionOperators/numeric/numericGreaterThan.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { numericGreaterThan } from './numericGreaterThan';

describe('numericGreaterThan', () => {
it('returns true', () => {
expect(numericGreaterThan(7, 5)).toBeTruthy;
expect(numericGreaterThan(8.2, 2.2)).toBeTruthy;
expect(numericGreaterThan(Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER)).toBeTruthy;
});

it('returns false', () => {
expect(numericGreaterThan(5, 7)).toBeFalsy;
expect(numericGreaterThan(-1, -1)).toBeFalsy;
expect(numericGreaterThan(Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)).toBeFalsy;
});
});
22 changes: 22 additions & 0 deletions src/conditionOperators/numeric/numericGreaterThan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Numeric greater than matching.
*
* @since 4.6.0
* @category Numeric
* @param {number} data The value to be compared.
* @param {number} expected The expected value.
* @returns {boolean} Returns `true` if `value` is greater than `expected value`.
* @example
* ```javascript
* numericGreaterThan(6, 5)
* // => true
*
* numericGreaterThan(4, 8)
* // => false
* ```
*/
export function numericGreaterThan(data: number, expected: number): boolean {
return (
data > expected
);
}

0 comments on commit 01384d0

Please sign in to comment.