-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber.spec.ts
32 lines (30 loc) · 1.25 KB
/
number.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as number from '@src/number';
describe('convertToZhCurrency test', () => {
it('should handle the minimum valid input', () => {
expect(number.convertToZhCurrency(0)).toBe('零元整');
});
it('should handle the maximum valid decimal input', () => {
const maxValue = Number.MAX_SAFE_INTEGER;
expect(number.convertToZhCurrency(maxValue)).toBe('玖仟零柒万亿壹仟玖佰玖拾贰亿伍仟肆佰柒拾肆万玖佰玖拾壹元整');
});
it('should handle numbers width multiple trailing zeros in decimal part', () => {
const input = 123.0;
expect(number.convertToZhCurrency(input)).toBe('壹佰贰拾叁元整');
});
it('should handle negative numbers', () => {
const input = -123.45;
expect(number.convertToZhCurrency(input)).toBe('负壹佰贰拾叁元肆角伍分');
});
it('should handle with max three decimals', () => {
const input = 123.4543;
expect(number.convertToZhCurrency(input)).toBe('壹佰贰拾叁元肆角伍分肆厘叁');
});
});
describe('toCurrency test', () => {
it('use local language format', () => {
expect(number.toCurrency(123.12, 'EUR')).toBe('€123.12');
});
it('give a language format', () => {
expect(number.toCurrency(123.12, 'CNY', 'zh-CN')).toBe('¥123.12');
});
});