Skip to content

Commit

Permalink
feat(tests): add currency test cases + update other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlozovei committed May 2, 2020
1 parent b31eda6 commit 62fe10d
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 14 deletions.
73 changes: 73 additions & 0 deletions tests/currency.test.js
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');
});
65 changes: 65 additions & 0 deletions tests/helpers.test.js
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');
});
16 changes: 8 additions & 8 deletions tests/languages.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import numbersToWords from '../index';
import fullNumbers from '../index';

test('Write a single number in portuguese', () => {
const options = {
value: 7,
lang: 'pt-BR'
};
const words = numbersToWords(options);
const words = fullNumbers(options);
expect(words).toBe('sete');
});

Expand All @@ -14,7 +14,7 @@ test('Write a dozen below 20 in portuguese', () => {
value: 13,
lang: 'pt-BR'
};
const words = numbersToWords(options);
const words = fullNumbers(options);
expect(words).toBe('treze');
});

Expand All @@ -23,7 +23,7 @@ test('Write a dozen above 20 in portuguese', () => {
value: 68,
lang: 'pt-BR'
};
const words = numbersToWords(options);
const words = fullNumbers(options);
expect(words).toBe('sessenta e oito');
});

Expand All @@ -32,7 +32,7 @@ test('Write a hundrer on singular in portuguese', () => {
value: 100,
lang: 'pt-BR'
};
const words = numbersToWords(options);
const words = fullNumbers(options);
expect(words).toBe('cem');
});

Expand All @@ -41,7 +41,7 @@ test('Write a hundrer on plural in portuguese', () => {
value: 120,
lang: 'pt-BR'
};
const words = numbersToWords(options);
const words = fullNumbers(options);
expect(words).toBe('cento e vinte');
});

Expand All @@ -50,7 +50,7 @@ test('Write a hundred in portuguese', () => {
value: 1234,
lang: 'pt-BR'
};
const words = numbersToWords(options);
const words = fullNumbers(options);
expect(words).toBe('um mil, duzentos e trinta e quatro');
});

Expand All @@ -59,6 +59,6 @@ test('Write a million in portuguese', () => {
value: 2750130,
lang: 'pt-BR'
};
const words = numbersToWords(options);
const words = fullNumbers(options);
expect(words).toBe('dois milhões, setecentos e cinquenta mil, cento e trinta');
});
12 changes: 6 additions & 6 deletions tests/values.test.js
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');
});

0 comments on commit 62fe10d

Please sign in to comment.