-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): add currency test cases + update other tests
- Loading branch information
Showing
4 changed files
with
152 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import fullNumbers from '../index'; | ||
|
||
test('Write a singular value', () => { | ||
const value = fullNumbers({ | ||
value: 1, | ||
currency: { | ||
name: { | ||
plural: 'dollars', | ||
singular: 'dollar' | ||
}, | ||
decimals: { | ||
plural: 'cents', | ||
singular: 'cent' | ||
} | ||
} | ||
}); | ||
|
||
expect(value).toBe('one dollar'); | ||
}); | ||
|
||
test('Write a singular value with decimals', () => { | ||
const value = fullNumbers({ | ||
value: 1.99, | ||
currency: { | ||
name: { | ||
plural: 'dollars', | ||
singular: 'dollar' | ||
}, | ||
decimals: { | ||
plural: 'cents', | ||
singular: 'cent' | ||
} | ||
} | ||
}); | ||
|
||
expect(value).toBe('one dollar with ninety-nine cents'); | ||
}); | ||
|
||
test('Write a plural value', () => { | ||
const value = fullNumbers({ | ||
value: 5, | ||
currency: { | ||
name: { | ||
plural: 'dollars', | ||
singular: 'dollar' | ||
}, | ||
decimals: { | ||
plural: 'cents', | ||
singular: 'cent' | ||
} | ||
} | ||
}); | ||
|
||
expect(value).toBe('five dollars'); | ||
}); | ||
|
||
test('Write a plural value with decimals', () => { | ||
const value = fullNumbers({ | ||
value: 12.5, | ||
currency: { | ||
name: { | ||
plural: 'dollars', | ||
singular: 'dollar' | ||
}, | ||
decimals: { | ||
plural: 'cents', | ||
singular: 'cent' | ||
} | ||
} | ||
}); | ||
|
||
expect(value).toBe('twelve dollars with fifty cents'); | ||
}); |
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,65 @@ | ||
import isFinite from '../src/helpers/isFinite'; | ||
import isFloat from '../src/helpers/isFloat'; | ||
import isSafeNumber from '../src/helpers/isSafeNumber'; | ||
import getDecimals from '../src/helpers/getDecimals'; | ||
import padNumber from '../src/helpers/padNumber'; | ||
|
||
test('Is a finite number', () => { | ||
const finite = isFinite(10); | ||
expect(finite).toBe(true); | ||
}); | ||
|
||
test('Is not a finite number', () => { | ||
const finite = isFinite(Infinity); | ||
expect(finite).toBe(false); | ||
}); | ||
|
||
test('Is a float', () => { | ||
const float = isFloat(430.2); | ||
expect(float).toBe(true); | ||
}); | ||
|
||
test('Is not a float', () => { | ||
const float = isFloat(430); | ||
expect(float).toBe(false); | ||
}); | ||
|
||
test('Is a safe number', () => { | ||
const safe = isSafeNumber(2000000); | ||
expect(safe).toBe(true); | ||
}); | ||
|
||
test('Is not a safe number', () => { | ||
const safe = isFloat(9007199254740992); | ||
expect(safe).toBe(false); | ||
}); | ||
|
||
test('Get decimals w/ 1', () => { | ||
const decimals = getDecimals(200.4); | ||
expect(decimals).toBe('4'); | ||
}); | ||
|
||
test('Get decimals w/ 2', () => { | ||
const decimals = getDecimals(200.45); | ||
expect(decimals).toBe('45'); | ||
}); | ||
|
||
test('Get decimals w/ 3', () => { | ||
const decimals = getDecimals(200.456); | ||
expect(decimals).toBe('456'); | ||
}); | ||
|
||
test('Pad number w/ 1', () => { | ||
const padded = padNumber(5); | ||
expect(padded).toBe('50'); | ||
}); | ||
|
||
test('Pad number w/ 2', () => { | ||
const padded = padNumber(60); | ||
expect(padded).toBe('60'); | ||
}); | ||
|
||
test('Pad number w/ 3', () => { | ||
const padded = padNumber(700); | ||
expect(padded).toBe('70'); | ||
}); |
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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
import numbersToWords from '../index'; | ||
import fullNumbers from '../index'; | ||
|
||
test('Write a single number', () => { | ||
const words = numbersToWords(5); | ||
const words = fullNumbers(5); | ||
expect(words).toBe('five'); | ||
}); | ||
|
||
test('Write a dozen below 20', () => { | ||
const words = numbersToWords(14); | ||
const words = fullNumbers(14); | ||
expect(words).toBe('fourteen'); | ||
}); | ||
|
||
test('Write a dozen above 20', () => { | ||
const words = numbersToWords(52); | ||
const words = fullNumbers(52); | ||
expect(words).toBe('fifty-two'); | ||
}); | ||
|
||
test('Write a hundred', () => { | ||
const words = numbersToWords(320); | ||
const words = fullNumbers(320); | ||
expect(words).toBe('three hundred and twenty'); | ||
}); | ||
|
||
test('Write a million', () => { | ||
const words = numbersToWords(4520350); | ||
const words = fullNumbers(4520350); | ||
expect(words).toBe('four million, five hundred and twenty thousand, three hundred and fifty'); | ||
}); |