Skip to content

Commit d834f16

Browse files
Update hanzi2num tests
1 parent 1fc586d commit d834f16

File tree

1 file changed

+114
-18
lines changed

1 file changed

+114
-18
lines changed

test/hanzi2num.test.js

Lines changed: 114 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ var { num2hanzi, hanzi2num } = require("../src/hanzi2num");
44
describe("hanzi2num", () => {
55
describe("num2hanzi(0.53212121222)", () => {
66
it("should translate float number to hanzi correctly", () => {
7-
assert.equal(num2hanzi(0.53212121222), "零又五分三釐二毫一絲二忽一微");
7+
assert.equal(num2hanzi(0.53212121222), "五分三釐二毫一絲二忽一微二纖一沙二塵二埃二渺");
88
});
99
});
1010

1111
describe("num2hanzi(0.5)", () => {
1212
it("should translate float number to hanzi correctly", () => {
13-
assert.equal(num2hanzi(0.5), "零又五分");
13+
assert.equal(num2hanzi(0.5), "五分");
1414
});
1515
});
1616

@@ -28,7 +28,7 @@ describe("hanzi2num", () => {
2828
"二十一京二千三百四十五兆六千七百八十億零九百萬零二百五十有一"
2929
)
3030
),
31-
"二十一京二千三百四十五兆六千七百八十億九百萬零二百五十六"
31+
"二十一京二千三百四十五兆六千七百八十億零九百萬零二百六十"
3232
);
3333
});
3434
});
@@ -47,7 +47,7 @@ describe("hanzi2num", () => {
4747

4848
describe("num2hanzi(-0.765433)", () => {
4949
it("should translate negative float number", () => {
50-
assert.equal(num2hanzi(-0.765433), "負零又七分六釐五毫四絲三忽二微");
50+
assert.equal(num2hanzi(-0.765433), "負七分六釐五毫四絲三忽三微");
5151
});
5252
});
5353

@@ -59,7 +59,7 @@ describe("hanzi2num", () => {
5959

6060
describe('hanzi2num("一沙一塵")', () => {
6161
it("should translate hanzi to number correctly", () => {
62-
assert.equal(hanzi2num("一沙一塵"), 1.0001000000000008e-8);
62+
assert.equal(hanzi2num("一沙一塵"), 1.1e-8);
6363
});
6464
});
6565

@@ -74,9 +74,9 @@ describe("hanzi2num", () => {
7474
});
7575
});
7676

77-
describe('hanzi2num("無量大數")', () => {
77+
describe('hanzi2num("")', () => {
7878
it("should translate hanzi to number correctly", () => {
79-
assert.equal(hanzi2num("無量大數"), 1.0000000000000002e68);
79+
assert.equal(hanzi2num(""), 1e+48);
8080
});
8181
});
8282

@@ -86,24 +86,24 @@ describe("hanzi2num", () => {
8686
});
8787
});
8888

89-
describe('hanzi2num("二分七釐三毫一絲二忽三微四纖五沙三千萬塵一埃")', () => {
89+
describe('hanzi2num("二分七釐三毫一絲二忽三微四纖五沙三塵一埃")', () => {
9090
it("should translate hanzi to number correctly", () => {
9191
assert.equal(
92-
hanzi2num("二分七釐三毫一絲二忽三微四纖五沙三千萬塵一埃"),
93-
0.2731234529990001
92+
hanzi2num("二分七釐三毫一絲二忽三微四纖五沙三塵一埃"),
93+
0.2731234531
9494
);
9595
});
9696
});
9797

98-
describe('hanzi2num("剎那")', () => {
98+
describe('hanzi2num("一漠")', () => {
9999
it("should translate hanzi to number correctly", () => {
100-
assert.equal(hanzi2num("剎那"), 1.000000000000001e-48);
100+
assert.equal(hanzi2num("一漠"), 1e-12);
101101
});
102102
});
103103

104104
describe('hanzi2num("三千萬埃")', () => {
105105
it("should translate hanzi to number correctly", () => {
106-
assert.equal(hanzi2num("三千萬埃"), 2.9990000000000027e-13);
106+
assert.equal(hanzi2num("三千萬埃"), 0.003);
107107
});
108108
});
109109

@@ -113,9 +113,9 @@ describe("hanzi2num", () => {
113113
});
114114
});
115115

116-
describe('hanzi2num("不可思議")', () => {
116+
describe('hanzi2num("極極極極極極")', () => {
117117
it("should translate hanzi to number correctly", () => {
118-
assert.equal(hanzi2num("不可思議"), 1.0000000000000002e64);
118+
assert.equal(hanzi2num("極極極極極極"), 1e288);
119119
});
120120
});
121121

@@ -133,7 +133,7 @@ describe("hanzi2num", () => {
133133

134134
describe('hanzi2num("二百五")', () => {
135135
it("should translate hanzi to number correctly", () => {
136-
assert.equal(hanzi2num("二百五"), 250);
136+
assert.equal(hanzi2num("二百五"), 205);
137137
});
138138
});
139139

@@ -145,13 +145,13 @@ describe("hanzi2num", () => {
145145

146146
describe('hanzi2num("三千七")', () => {
147147
it("should translate hanzi to number correctly", () => {
148-
assert.equal(hanzi2num("三千七"), 3700);
148+
assert.equal(hanzi2num("三千七"), 3007);
149149
});
150150
});
151151

152152
describe('hanzi2num("五萬三千七")', () => {
153153
it("should translate hanzi to number correctly", () => {
154-
assert.equal(hanzi2num("五萬三千七"), 53700);
154+
assert.equal(hanzi2num("五萬三千七"), 53007);
155155
});
156156
});
157157

@@ -160,4 +160,100 @@ describe("hanzi2num", () => {
160160
assert.equal(hanzi2num("五萬三千零七"), 53007);
161161
});
162162
});
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+
});
163259
});

0 commit comments

Comments
 (0)