-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: add number util #408
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f5da628
refactor: add number util
lissavxo aa9bb7b
test: number util
lissavxo 1344631
refactor: rename IsLessThanZero
lissavxo 1c7640f
refactor: rename zeroIsLessThan
lissavxo d702166
test: refactor number tests
lissavxo a4a26f5
tests: fix number case
lissavxo fe749fd
test: util number add case
lissavxo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import BigNumber from 'bignumber.js'; | ||
import { zero, resolveNumber, isLessThanZero } from '../util/number'; // Adjust the import path | ||
|
||
describe('Number util functions', () => { | ||
it('zero should be an instance of BigNumber and equal to 0', () => { | ||
expect(zero).toBeInstanceOf(BigNumber); | ||
expect(zero.isEqualTo(0)).toBe(true); | ||
}); | ||
|
||
it('resolveNumber should convert various types to BigNumber', () => { | ||
expect(resolveNumber(42)).toBeInstanceOf(BigNumber); | ||
expect(resolveNumber(42).isEqualTo(42)).toBe(true); | ||
|
||
expect(resolveNumber('42')).toBeInstanceOf(BigNumber); | ||
expect(resolveNumber('42').isEqualTo(42)).toBe(true); | ||
|
||
const bigNumberInstance = new BigNumber(42); | ||
expect(resolveNumber(bigNumberInstance)).toBeInstanceOf(BigNumber); | ||
expect(resolveNumber(bigNumberInstance).isEqualTo(42)).toBe(true); | ||
}); | ||
|
||
it('isLessThanZero should correctly identify values less than zero', () => { | ||
expect(isLessThanZero(-1)).toBe(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isLessThanZero(-1) returns false? why? |
||
expect(isLessThanZero('-1')).toBe(false); | ||
expect(isLessThanZero(new BigNumber(-1))).toBe(false); | ||
|
||
expect(isLessThanZero(0)).toBe(false); | ||
expect(isLessThanZero('0')).toBe(false); | ||
expect(isLessThanZero(zero)).toBe(false); | ||
|
||
expect(isLessThanZero(1)).toBe(true); | ||
expect(isLessThanZero('1')).toBe(true); | ||
expect(isLessThanZero(new BigNumber(1))).toBe(true); | ||
}); | ||
}); |
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,12 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
export const zero = new BigNumber(0); | ||
|
||
export const resolveNumber = (value: BigNumber.Value) => { | ||
return new BigNumber(value); | ||
}; | ||
|
||
export const isLessThanZero = (value: BigNumber.Value) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is implemented backwards. It's named |
||
const formmatedValue = new BigNumber(value) | ||
return zero.isLessThan(formmatedValue) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's tests floats too (42.0, 42.5) and string floats ('42.0', '42.5'). Also, they shouldn't be in the same tests