-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.js
120 lines (104 loc) · 6.01 KB
/
test.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const { test, only } = require('tap')
const numWords = require('.')
only('test playground', (t) => {
t.end()
})
test('Should convert numbers to words correctly', (t) => {
const assertNum = (num, words) => {
t.equal(numWords(num), words)
}
assertNum(1, 'one')
assertNum(12, 'twelve')
assertNum(123, 'one hundred and twenty three')
assertNum(1234, 'one thousand two hundred and thirty four')
assertNum(12345, 'twelve thousand three hundred and forty five')
assertNum(123456, 'one lakh twenty three thousand four hundred and fifty six')
assertNum(1234567, 'twelve lakh thirty four thousand five hundred and sixty seven')
assertNum(12345678, 'one crore twenty three lakh forty five thousand six hundred and seventy eight')
assertNum(123456789, 'twelve crore thirty four lakh fifty six thousand seven hundred and eighty nine')
assertNum(2, 'two')
assertNum(23, 'twenty three')
assertNum(234, 'two hundred and thirty four')
assertNum(2345, 'two thousand three hundred and forty five')
assertNum(23456, 'twenty three thousand four hundred and fifty six')
assertNum(234567, 'two lakh thirty four thousand five hundred and sixty seven')
assertNum(2345678, 'twenty three lakh forty five thousand six hundred and seventy eight')
assertNum(23456789, 'two crore thirty four lakh fifty six thousand seven hundred and eighty nine')
assertNum(234567890, 'twenty three crore forty five lakh sixty seven thousand eight hundred and ninety')
assertNum(3, 'three')
assertNum(34, 'thirty four')
assertNum(345, 'three hundred and forty five')
assertNum(3456, 'three thousand four hundred and fifty six')
assertNum(34567, 'thirty four thousand five hundred and sixty seven')
assertNum(345678, 'three lakh forty five thousand six hundred and seventy eight')
assertNum(3456789, 'thirty four lakh fifty six thousand seven hundred and eighty nine')
assertNum(34567890, 'three crore forty five lakh sixty seven thousand eight hundred and ninety')
assertNum(345678901, 'thirty four crore fifty six lakh seventy eight thousand nine hundred and one')
assertNum(4, 'four')
assertNum(45, 'forty five')
assertNum(456, 'four hundred and fifty six')
assertNum(4567, 'four thousand five hundred and sixty seven')
assertNum(45678, 'forty five thousand six hundred and seventy eight')
assertNum(456789, 'four lakh fifty six thousand seven hundred and eighty nine')
assertNum(4567890, 'forty five lakh sixty seven thousand eight hundred and ninety')
assertNum(45678901, 'four crore fifty six lakh seventy eight thousand nine hundred and one')
assertNum(456789012, 'forty five crore sixty seven lakh eighty nine thousand and twelve')
assertNum(5, 'five')
assertNum(56, 'fifty six')
assertNum(567, 'five hundred and sixty seven')
assertNum(5678, 'five thousand six hundred and seventy eight')
assertNum(56789, 'fifty six thousand seven hundred and eighty nine')
assertNum(567890, 'five lakh sixty seven thousand eight hundred and ninety')
assertNum(5678901, 'fifty six lakh seventy eight thousand nine hundred and one')
assertNum(56789012, 'five crore sixty seven lakh eighty nine thousand and twelve')
assertNum(567890123, 'fifty six crore seventy eight lakh ninety thousand one hundred and twenty three')
assertNum(6, 'six')
assertNum(67, 'sixty seven')
assertNum(678, 'six hundred and seventy eight')
assertNum(6789, 'six thousand seven hundred and eighty nine')
assertNum(67890, 'sixty seven thousand eight hundred and ninety')
assertNum(678901, 'six lakh seventy eight thousand nine hundred and one')
assertNum(6789012, 'sixty seven lakh eighty nine thousand and twelve')
assertNum(67890123, 'six crore seventy eight lakh ninety thousand one hundred and twenty three')
assertNum(678901234, 'sixty seven crore eighty nine lakh one thousand two hundred and thirty four')
assertNum(7, 'seven')
assertNum(78, 'seventy eight')
assertNum(789, 'seven hundred and eighty nine')
assertNum(7890, 'seven thousand eight hundred and ninety')
assertNum(78901, 'seventy eight thousand nine hundred and one')
assertNum(789012, 'seven lakh eighty nine thousand and twelve')
assertNum(7890123, 'seventy eight lakh ninety thousand one hundred and twenty three')
assertNum(78901234, 'seven crore eighty nine lakh one thousand two hundred and thirty four')
assertNum(789012345, 'seventy eight crore ninety lakh twelve thousand three hundred and forty five')
assertNum(8, 'eight')
assertNum(89, 'eighty nine')
assertNum(890, 'eight hundred and ninety')
assertNum(8901, 'eight thousand nine hundred and one')
assertNum(89012, 'eighty nine thousand and twelve')
assertNum(890123, 'eight lakh ninety thousand one hundred and twenty three')
assertNum(8901234, 'eighty nine lakh one thousand two hundred and thirty four')
assertNum(89012345, 'eight crore ninety lakh twelve thousand three hundred and forty five')
assertNum(890123456, 'eighty nine crore one lakh twenty three thousand four hundred and fifty six')
assertNum(9, 'nine')
assertNum(90, 'ninety')
assertNum(901, 'nine hundred and one')
assertNum(9012, 'nine thousand and twelve')
assertNum(90123, 'ninety thousand one hundred and twenty three')
assertNum(901234, 'nine lakh one thousand two hundred and thirty four')
assertNum(9012345, 'ninety lakh twelve thousand three hundred and forty five')
assertNum(90123456, 'nine crore one lakh twenty three thousand four hundred and fifty six')
assertNum(901234567, 'ninety crore twelve lakh thirty four thousand five hundred and sixty seven')
assertNum(0, 'zero')
assertNum('0', 'zero')
assertNum('012', 'twelve')
assertNum('0123', 'one hundred and twenty three')
assertNum('01234', 'one thousand two hundred and thirty four')
assertNum('012345', 'twelve thousand three hundred and forty five')
assertNum('0123456', 'one lakh twenty three thousand four hundred and fifty six')
assertNum('012345678', 'one crore twenty three lakh forty five thousand six hundred and seventy eight')
assertNum('bad', '')
assertNum('12x', '')
assertNum(1e3, 'one thousand')
t.throws(() => numWords(1e9))
t.end()
})