@@ -4,13 +4,13 @@ var { num2hanzi, hanzi2num } = require("../src/hanzi2num");
4
4
describe ( "hanzi2num" , ( ) => {
5
5
describe ( "num2hanzi(0.53212121222)" , ( ) => {
6
6
it ( "should translate float number to hanzi correctly" , ( ) => {
7
- assert . equal ( num2hanzi ( 0.53212121222 ) , "零又五分三釐二毫一絲二忽一微 " ) ;
7
+ assert . equal ( num2hanzi ( 0.53212121222 ) , "五分三釐二毫一絲二忽一微二纖一沙二塵二埃二渺 " ) ;
8
8
} ) ;
9
9
} ) ;
10
10
11
11
describe ( "num2hanzi(0.5)" , ( ) => {
12
12
it ( "should translate float number to hanzi correctly" , ( ) => {
13
- assert . equal ( num2hanzi ( 0.5 ) , "零又五分 " ) ;
13
+ assert . equal ( num2hanzi ( 0.5 ) , "五分 " ) ;
14
14
} ) ;
15
15
} ) ;
16
16
@@ -28,7 +28,7 @@ describe("hanzi2num", () => {
28
28
"二十一京二千三百四十五兆六千七百八十億零九百萬零二百五十有一"
29
29
)
30
30
) ,
31
- "二十一京二千三百四十五兆六千七百八十億九百萬零二百五十六 "
31
+ "二十一京二千三百四十五兆六千七百八十億零九百萬零二百六十 "
32
32
) ;
33
33
} ) ;
34
34
} ) ;
@@ -47,7 +47,7 @@ describe("hanzi2num", () => {
47
47
48
48
describe ( "num2hanzi(-0.765433)" , ( ) => {
49
49
it ( "should translate negative float number" , ( ) => {
50
- assert . equal ( num2hanzi ( - 0.765433 ) , "負零又七分六釐五毫四絲三忽二微 " ) ;
50
+ assert . equal ( num2hanzi ( - 0.765433 ) , "負七分六釐五毫四絲三忽三微 " ) ;
51
51
} ) ;
52
52
} ) ;
53
53
@@ -59,7 +59,7 @@ describe("hanzi2num", () => {
59
59
60
60
describe ( 'hanzi2num("一沙一塵")' , ( ) => {
61
61
it ( "should translate hanzi to number correctly" , ( ) => {
62
- assert . equal ( hanzi2num ( "一沙一塵" ) , 1.0001000000000008e -8 ) ;
62
+ assert . equal ( hanzi2num ( "一沙一塵" ) , 1.1e -8 ) ;
63
63
} ) ;
64
64
} ) ;
65
65
@@ -74,9 +74,9 @@ describe("hanzi2num", () => {
74
74
} ) ;
75
75
} ) ;
76
76
77
- describe ( 'hanzi2num("無量大數 ")' , ( ) => {
77
+ describe ( 'hanzi2num("極 ")' , ( ) => {
78
78
it ( "should translate hanzi to number correctly" , ( ) => {
79
- assert . equal ( hanzi2num ( "無量大數 " ) , 1.0000000000000002e68 ) ;
79
+ assert . equal ( hanzi2num ( "極 " ) , 1e+48 ) ;
80
80
} ) ;
81
81
} ) ;
82
82
@@ -86,24 +86,24 @@ describe("hanzi2num", () => {
86
86
} ) ;
87
87
} ) ;
88
88
89
- describe ( 'hanzi2num("二分七釐三毫一絲二忽三微四纖五沙三千萬塵一埃 ")' , ( ) => {
89
+ describe ( 'hanzi2num("二分七釐三毫一絲二忽三微四纖五沙三塵一埃 ")' , ( ) => {
90
90
it ( "should translate hanzi to number correctly" , ( ) => {
91
91
assert . equal (
92
- hanzi2num ( "二分七釐三毫一絲二忽三微四纖五沙三千萬塵一埃 " ) ,
93
- 0.2731234529990001
92
+ hanzi2num ( "二分七釐三毫一絲二忽三微四纖五沙三塵一埃 " ) ,
93
+ 0.2731234531
94
94
) ;
95
95
} ) ;
96
96
} ) ;
97
97
98
- describe ( 'hanzi2num("剎那 ")' , ( ) => {
98
+ describe ( 'hanzi2num("一漠 ")' , ( ) => {
99
99
it ( "should translate hanzi to number correctly" , ( ) => {
100
- assert . equal ( hanzi2num ( "剎那 " ) , 1.000000000000001e-48 ) ;
100
+ assert . equal ( hanzi2num ( "一漠 " ) , 1e-12 ) ;
101
101
} ) ;
102
102
} ) ;
103
103
104
104
describe ( 'hanzi2num("三千萬埃")' , ( ) => {
105
105
it ( "should translate hanzi to number correctly" , ( ) => {
106
- assert . equal ( hanzi2num ( "三千萬埃" ) , 2.9990000000000027e-13 ) ;
106
+ assert . equal ( hanzi2num ( "三千萬埃" ) , 0.003 ) ;
107
107
} ) ;
108
108
} ) ;
109
109
@@ -113,9 +113,9 @@ describe("hanzi2num", () => {
113
113
} ) ;
114
114
} ) ;
115
115
116
- describe ( 'hanzi2num("不可思議 ")' , ( ) => {
116
+ describe ( 'hanzi2num("極極極極極極 ")' , ( ) => {
117
117
it ( "should translate hanzi to number correctly" , ( ) => {
118
- assert . equal ( hanzi2num ( "不可思議 " ) , 1.0000000000000002e64 ) ;
118
+ assert . equal ( hanzi2num ( "極極極極極極 " ) , 1e288 ) ;
119
119
} ) ;
120
120
} ) ;
121
121
@@ -133,7 +133,7 @@ describe("hanzi2num", () => {
133
133
134
134
describe ( 'hanzi2num("二百五")' , ( ) => {
135
135
it ( "should translate hanzi to number correctly" , ( ) => {
136
- assert . equal ( hanzi2num ( "二百五" ) , 250 ) ;
136
+ assert . equal ( hanzi2num ( "二百五" ) , 205 ) ;
137
137
} ) ;
138
138
} ) ;
139
139
@@ -145,13 +145,13 @@ describe("hanzi2num", () => {
145
145
146
146
describe ( 'hanzi2num("三千七")' , ( ) => {
147
147
it ( "should translate hanzi to number correctly" , ( ) => {
148
- assert . equal ( hanzi2num ( "三千七" ) , 3700 ) ;
148
+ assert . equal ( hanzi2num ( "三千七" ) , 3007 ) ;
149
149
} ) ;
150
150
} ) ;
151
151
152
152
describe ( 'hanzi2num("五萬三千七")' , ( ) => {
153
153
it ( "should translate hanzi to number correctly" , ( ) => {
154
- assert . equal ( hanzi2num ( "五萬三千七" ) , 53700 ) ;
154
+ assert . equal ( hanzi2num ( "五萬三千七" ) , 53007 ) ;
155
155
} ) ;
156
156
} ) ;
157
157
@@ -160,4 +160,100 @@ describe("hanzi2num", () => {
160
160
assert . equal ( hanzi2num ( "五萬三千零七" ) , 53007 ) ;
161
161
} ) ;
162
162
} ) ;
163
+
164
+ describe ( 'hanzi2num("十萬")' , ( ) => {
165
+ it ( "should translate hanzi to number correctly" , ( ) => {
166
+ assert . equal ( hanzi2num ( "十萬" ) , 1e+5 ) ;
167
+ } ) ;
168
+ } ) ;
169
+
170
+ describe ( 'hanzi2num("萬十")' , ( ) => {
171
+ it ( "should translate hanzi to number correctly" , ( ) => {
172
+ assert . equal ( hanzi2num ( "萬十" ) , 10010 ) ;
173
+ } ) ;
174
+ } ) ;
175
+
176
+ describe ( 'hanzi2num("萬億")' , ( ) => {
177
+ it ( "should translate hanzi to number correctly" , ( ) => {
178
+ assert . equal ( hanzi2num ( "萬億" ) , 1e+12 ) ;
179
+ } ) ;
180
+ } ) ;
181
+
182
+ describe ( 'hanzi2num("億萬")' , ( ) => {
183
+ it ( "should translate hanzi to number correctly" , ( ) => {
184
+ assert . equal ( hanzi2num ( "億萬" ) , 100010000 ) ;
185
+ } ) ;
186
+ } ) ;
187
+
188
+ describe ( 'hanzi2num("三·一四一五九二六五三五八九七九三")' , ( ) => {
189
+ it ( "should translate hanzi to number correctly" , ( ) => {
190
+ assert . equal ( hanzi2num ( "三·一四一五九二六五三五八九七九三" ) , Math . PI ) ;
191
+ } ) ;
192
+ } ) ;
193
+
194
+ describe ( 'hanzi2num("一二京三四五六兆七〇〇〇億")' , ( ) => {
195
+ it ( "should translate hanzi to number correctly" , ( ) => {
196
+ assert . equal ( hanzi2num ( "一二京三四五六兆七〇〇〇億" ) , 1.234567e+17 ) ;
197
+ } ) ;
198
+ } ) ;
199
+
200
+ describe ( 'hanzi2num("一二京三四五六兆七〇〇〇〇億")' , ( ) => {
201
+ it ( "should reject invalid hanzi" , ( ) => {
202
+ assert . ok ( Number . isNaN ( hanzi2num ( "一二京三四五六兆七〇〇〇〇億" ) ) ) ;
203
+ } ) ;
204
+ } ) ;
205
+
206
+ describe ( 'hanzi2num("一百又五絲")' , ( ) => {
207
+ it ( "should translate hanzi to number correctly" , ( ) => {
208
+ assert . equal ( hanzi2num ( "一百又五絲" ) , 100.0005 ) ;
209
+ } ) ;
210
+ } ) ;
211
+
212
+ describe ( 'hanzi2num("一百零五絲")' , ( ) => {
213
+ it ( "should translate hanzi to number correctly" , ( ) => {
214
+ assert . equal ( hanzi2num ( "一百零五絲" ) , 0.0105 ) ;
215
+ } ) ;
216
+ } ) ;
217
+
218
+ describe ( 'hanzi2num("一千又五百")' , ( ) => {
219
+ it ( "should translate hanzi to number correctly" , ( ) => {
220
+ assert . equal ( hanzi2num ( "一千又五百" ) , 1500 ) ;
221
+ } ) ;
222
+ } ) ;
223
+
224
+ describe ( 'hanzi2num("一千零五百")' , ( ) => {
225
+ it ( "should reject invalid hanzi" , ( ) => {
226
+ assert . ok ( Number . isNaN ( hanzi2num ( "一千零五百" ) ) ) ;
227
+ } ) ;
228
+ } ) ;
229
+
230
+ describe ( 'hanzi2num("五毫絲")' , ( ) => {
231
+ it ( "should reject invalid hanzi" , ( ) => {
232
+ assert . ok ( Number . isNaN ( hanzi2num ( "五毫絲" ) ) ) ;
233
+ } ) ;
234
+ } ) ;
235
+
236
+ describe ( 'hanzi2num("五又十分")' , ( ) => {
237
+ it ( "should reject invalid hanzi" , ( ) => {
238
+ assert . ok ( Number . isNaN ( hanzi2num ( "五又十分" ) ) ) ;
239
+ } ) ;
240
+ } ) ;
241
+
242
+ describe ( 'hanzi2num("十分")' , ( ) => {
243
+ it ( "should translate hanzi to number correctly" , ( ) => {
244
+ assert . equal ( hanzi2num ( "十分" ) , 1 ) ;
245
+ } ) ;
246
+ } ) ;
247
+
248
+ describe ( 'hanzi2num("一分十")' , ( ) => {
249
+ it ( "should reject invalid hanzi" , ( ) => {
250
+ assert . ok ( Number . isNaN ( hanzi2num ( "一分十" ) ) ) ;
251
+ } ) ;
252
+ } ) ;
253
+
254
+ describe ( 'hanzi2num("一分十絲")' , ( ) => {
255
+ it ( "should translate hanzi to number correctly" , ( ) => {
256
+ assert . equal ( hanzi2num ( "一分十絲" ) , 0.101 ) ;
257
+ } ) ;
258
+ } ) ;
163
259
} ) ;
0 commit comments