@@ -8,59 +8,59 @@ describe('IncrementId', () => {
8
8
incrementId = new IncrementId ( ) ;
9
9
} ) ;
10
10
11
- describe ( '初始状态 ' , ( ) => {
12
- test ( '应该初始化为 0' , ( ) => {
11
+ describe ( 'initial state ' , ( ) => {
12
+ test ( 'should initialize with a value of 0' , ( ) => {
13
13
expect ( incrementId . equal ( 0 ) ) . toBe ( true ) ;
14
14
} ) ;
15
15
16
- test ( '应该不等于非零值 ' , ( ) => {
16
+ test ( 'should not be equal to non-zero values ' , ( ) => {
17
17
expect ( incrementId . equal ( 1 ) ) . toBe ( false ) ;
18
18
expect ( incrementId . equal ( - 1 ) ) . toBe ( false ) ;
19
19
expect ( incrementId . equal ( 100 ) ) . toBe ( false ) ;
20
20
} ) ;
21
21
} ) ;
22
22
23
- describe ( 'equal 方法 ' , ( ) => {
24
- test ( '应该正确比较相等的值 ' , ( ) => {
23
+ describe ( 'equal method ' , ( ) => {
24
+ test ( 'should correctly compare equal values ' , ( ) => {
25
25
expect ( incrementId . equal ( 0 ) ) . toBe ( true ) ;
26
26
27
- incrementId . next ( ) ; // 值变为 1
27
+ incrementId . next ( ) ; // value becomes 1
28
28
expect ( incrementId . equal ( 1 ) ) . toBe ( true ) ;
29
29
30
- incrementId . next ( ) ; // 值变为 2
30
+ incrementId . next ( ) ; // value becomes 2
31
31
expect ( incrementId . equal ( 2 ) ) . toBe ( true ) ;
32
32
} ) ;
33
33
34
- test ( '应该正确识别不相等的值 ' , ( ) => {
34
+ test ( 'should correctly identify unequal values ' , ( ) => {
35
35
expect ( incrementId . equal ( 1 ) ) . toBe ( false ) ;
36
36
expect ( incrementId . equal ( - 1 ) ) . toBe ( false ) ;
37
37
38
- incrementId . next ( ) ; // 值变为 1
38
+ incrementId . next ( ) ; // value becomes 1
39
39
expect ( incrementId . equal ( 0 ) ) . toBe ( false ) ;
40
40
expect ( incrementId . equal ( 2 ) ) . toBe ( false ) ;
41
41
} ) ;
42
42
43
- test ( '应该处理边界值 ' , ( ) => {
43
+ test ( 'should handle boundary values ' , ( ) => {
44
44
expect ( incrementId . equal ( Number . MAX_SAFE_INTEGER ) ) . toBe ( false ) ;
45
45
expect ( incrementId . equal ( Number . MIN_SAFE_INTEGER ) ) . toBe ( false ) ;
46
46
expect ( incrementId . equal ( Number . POSITIVE_INFINITY ) ) . toBe ( false ) ;
47
47
expect ( incrementId . equal ( Number . NEGATIVE_INFINITY ) ) . toBe ( false ) ;
48
48
} ) ;
49
49
50
- test ( '应该处理特殊数值 ' , ( ) => {
50
+ test ( 'should handle special numeric values ' , ( ) => {
51
51
expect ( incrementId . equal ( Number . NaN ) ) . toBe ( false ) ;
52
52
expect ( incrementId . equal ( 0.5 ) ) . toBe ( false ) ;
53
53
expect ( incrementId . equal ( - 0.5 ) ) . toBe ( false ) ;
54
54
} ) ;
55
55
} ) ;
56
56
57
- describe ( 'generate 方法 ' , ( ) => {
58
- test ( '应该从 1 开始生成 ' , ( ) => {
57
+ describe ( 'next method ' , ( ) => {
58
+ test ( 'should start generating IDs from 1 ' , ( ) => {
59
59
const firstId = incrementId . next ( ) ;
60
60
expect ( firstId ) . toBe ( 1 ) ;
61
61
} ) ;
62
62
63
- test ( '应该递增生成 ID ' , ( ) => {
63
+ test ( 'should generate incrementing IDs ' , ( ) => {
64
64
const id1 = incrementId . next ( ) ;
65
65
const id2 = incrementId . next ( ) ;
66
66
const id3 = incrementId . next ( ) ;
@@ -70,21 +70,21 @@ describe('IncrementId', () => {
70
70
expect ( id3 ) . toBe ( 3 ) ;
71
71
} ) ;
72
72
73
- test ( '应该连续生成唯一 ID ' , ( ) => {
73
+ test ( 'should generate a continuous sequence of unique IDs ' , ( ) => {
74
74
const ids : number [ ] = [ ] ;
75
75
for ( let i = 0 ; i < 100 ; i ++ ) {
76
76
ids . push ( incrementId . next ( ) ) ;
77
77
}
78
78
79
- // 检查所有 ID 都是唯一的
79
+ // Check that all IDs are unique
80
80
const uniqueIds = new Set ( ids ) ;
81
81
expect ( uniqueIds . size ) . toBe ( ids . length ) ;
82
82
83
- // 检查 ID 是连续的
83
+ // Check that IDs are sequential
84
84
expect ( ids ) . toEqual ( Array . from ( { length : 100 } , ( _ , i ) => i + 1 ) ) ;
85
85
} ) ;
86
86
87
- test ( '生成后 equal 方法应该反映新值 ' , ( ) => {
87
+ test ( 'equal method should reflect the new value after generation ' , ( ) => {
88
88
expect ( incrementId . equal ( 0 ) ) . toBe ( true ) ;
89
89
90
90
const id1 = incrementId . next ( ) ;
@@ -96,7 +96,7 @@ describe('IncrementId', () => {
96
96
expect ( incrementId . equal ( id1 ) ) . toBe ( false ) ;
97
97
} ) ;
98
98
99
- test ( '应该返回生成的 ID 值 ' , ( ) => {
99
+ test ( 'should return the generated ID value ' , ( ) => {
100
100
for ( let i = 1 ; i <= 10 ; i ++ ) {
101
101
const generatedId = incrementId . next ( ) ;
102
102
expect ( generatedId ) . toBe ( i ) ;
@@ -105,8 +105,8 @@ describe('IncrementId', () => {
105
105
} ) ;
106
106
} ) ;
107
107
108
- describe ( '大量生成测试 ' , ( ) => {
109
- test ( '应该能够生成大量 ID 而不出错 ' , ( ) => {
108
+ describe ( 'large scale generation test ' , ( ) => {
109
+ test ( 'should be able to generate a large number of IDs without errors ' , ( ) => {
110
110
const count = 10000 ;
111
111
const ids : number [ ] = [ ] ;
112
112
@@ -121,8 +121,8 @@ describe('IncrementId', () => {
121
121
} ) ;
122
122
} ) ;
123
123
124
- describe ( '多个实例的独立性 ' , ( ) => {
125
- test ( '不同实例应该独立计数 ' , ( ) => {
124
+ describe ( 'multiple instances independence ' , ( ) => {
125
+ test ( 'different instances should count independently ' , ( ) => {
126
126
const id1 = new IncrementId ( ) ;
127
127
const id2 = new IncrementId ( ) ;
128
128
@@ -142,40 +142,40 @@ describe('多个实例的独立性', () => {
142
142
expect ( id2 . equal ( 1 ) ) . toBe ( false ) ;
143
143
} ) ;
144
144
145
- test ( '应该能够创建多个独立的实例 ' , ( ) => {
145
+ test ( 'should be able to create multiple independent instances ' , ( ) => {
146
146
const instances = Array . from ( { length : 5 } , ( ) => new IncrementId ( ) ) ;
147
147
148
- // 每个实例都从 1 开始
148
+ // Each instance starts from 1
149
149
instances . forEach ( ( instance ) => {
150
150
expect ( instance . next ( ) ) . toBe ( 1 ) ;
151
151
} ) ;
152
152
153
- // 每个实例都独立计数
153
+ // Each instance counts independently
154
154
instances . forEach ( ( instance ) => {
155
155
expect ( instance . next ( ) ) . toBe ( 2 ) ;
156
156
expect ( instance . equal ( 2 ) ) . toBe ( true ) ;
157
157
} ) ;
158
158
} ) ;
159
159
} ) ;
160
160
161
- describe ( '边界情况和错误处理 ' , ( ) => {
161
+ describe ( 'edge cases and error handling ' , ( ) => {
162
162
let incrementId : IncrementId ;
163
163
164
164
beforeEach ( ( ) => {
165
165
incrementId = new IncrementId ( ) ;
166
166
} ) ;
167
167
168
- test ( 'equal 方法应该处理非数字参数 ' , ( ) => {
169
- // TypeScript 会在编译时捕获这些错误,但在运行时测试行为
168
+ test ( 'equal method should handle non-numeric arguments ' , ( ) => {
169
+ // TypeScript catches these errors at compile time, but this tests the runtime behavior
170
170
expect ( incrementId . equal ( null as any ) ) . toBe ( false ) ;
171
171
expect ( incrementId . equal ( undefined as any ) ) . toBe ( false ) ;
172
172
expect ( incrementId . equal ( '1' as any ) ) . toBe ( false ) ;
173
173
expect ( incrementId . equal ( { } as any ) ) . toBe ( false ) ;
174
174
expect ( incrementId . equal ( [ ] as any ) ) . toBe ( false ) ;
175
175
} ) ;
176
176
177
- test ( '应该能处理大量调用而不溢出(在合理范围内) ' , ( ) => {
178
- // 测试相对较大的数值,但不到会导致性能问题的程度
177
+ test ( 'should handle a large number of calls without overflow (within reasonable limits) ' , ( ) => {
178
+ // Test with a relatively large number of calls, but not enough to cause performance issues
179
179
for ( let i = 0 ; i < 1000 ; i ++ ) {
180
180
const id = incrementId . next ( ) ;
181
181
expect ( id ) . toBe ( i + 1 ) ;
0 commit comments