-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathIterableEdgeInsets.test.ts
More file actions
347 lines (290 loc) · 10.8 KB
/
Copy pathIterableEdgeInsets.test.ts
File metadata and controls
347 lines (290 loc) · 10.8 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import { IterableEdgeInsets } from './IterableEdgeInsets';
import type { IterableEdgeInsetDetails } from '../types';
describe('IterableEdgeInsets', () => {
describe('constructor', () => {
it('should create instance with valid parameters', () => {
// GIVEN valid edge inset parameters
const top = 10;
const left = 20;
const bottom = 30;
const right = 40;
// WHEN creating an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(top, left, bottom, right);
// THEN it should have the correct properties
expect(edgeInsets.top).toBe(top);
expect(edgeInsets.left).toBe(left);
expect(edgeInsets.bottom).toBe(bottom);
expect(edgeInsets.right).toBe(right);
});
it('should create instance with zero values', () => {
// GIVEN zero edge inset parameters
const top = 0;
const left = 0;
const bottom = 0;
const right = 0;
// WHEN creating an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(top, left, bottom, right);
// THEN it should have zero values
expect(edgeInsets.top).toBe(0);
expect(edgeInsets.left).toBe(0);
expect(edgeInsets.bottom).toBe(0);
expect(edgeInsets.right).toBe(0);
});
it('should create instance with negative values', () => {
// GIVEN negative edge inset parameters
const top = -5;
const left = -10;
const bottom = -15;
const right = -20;
// WHEN creating an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(top, left, bottom, right);
// THEN it should have the negative values
expect(edgeInsets.top).toBe(-5);
expect(edgeInsets.left).toBe(-10);
expect(edgeInsets.bottom).toBe(-15);
expect(edgeInsets.right).toBe(-20);
});
it('should create instance with decimal values', () => {
// GIVEN decimal edge inset parameters
const top = 1.5;
const left = 2.7;
const bottom = 3.9;
const right = 4.1;
// WHEN creating an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(top, left, bottom, right);
// THEN it should have the decimal values
expect(edgeInsets.top).toBe(1.5);
expect(edgeInsets.left).toBe(2.7);
expect(edgeInsets.bottom).toBe(3.9);
expect(edgeInsets.right).toBe(4.1);
});
it('should create instance with large values', () => {
// GIVEN large edge inset parameters
const top = 1000;
const left = 2000;
const bottom = 3000;
const right = 4000;
// WHEN creating an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(top, left, bottom, right);
// THEN it should have the large values
expect(edgeInsets.top).toBe(1000);
expect(edgeInsets.left).toBe(2000);
expect(edgeInsets.bottom).toBe(3000);
expect(edgeInsets.right).toBe(4000);
});
});
describe('fromDict', () => {
it('should create instance from valid dictionary', () => {
// GIVEN a valid dictionary with edge inset details
const dict: IterableEdgeInsetDetails = {
top: 10,
left: 20,
bottom: 30,
right: 40
};
// WHEN creating from dictionary
const edgeInsets = IterableEdgeInsets.fromDict(dict);
// THEN it should have the correct properties
expect(edgeInsets.top).toBe(10);
expect(edgeInsets.left).toBe(20);
expect(edgeInsets.bottom).toBe(30);
expect(edgeInsets.right).toBe(40);
});
it('should create instance from dictionary with zero values', () => {
// GIVEN a dictionary with zero values
const dict: IterableEdgeInsetDetails = {
top: 0,
left: 0,
bottom: 0,
right: 0
};
// WHEN creating from dictionary
const edgeInsets = IterableEdgeInsets.fromDict(dict);
// THEN it should have zero values
expect(edgeInsets.top).toBe(0);
expect(edgeInsets.left).toBe(0);
expect(edgeInsets.bottom).toBe(0);
expect(edgeInsets.right).toBe(0);
});
it('should create instance from dictionary with negative values', () => {
// GIVEN a dictionary with negative values
const dict: IterableEdgeInsetDetails = {
top: -5,
left: -10,
bottom: -15,
right: -20
};
// WHEN creating from dictionary
const edgeInsets = IterableEdgeInsets.fromDict(dict);
// THEN it should have the negative values
expect(edgeInsets.top).toBe(-5);
expect(edgeInsets.left).toBe(-10);
expect(edgeInsets.bottom).toBe(-15);
expect(edgeInsets.right).toBe(-20);
});
it('should create instance from dictionary with decimal values', () => {
// GIVEN a dictionary with decimal values
const dict: IterableEdgeInsetDetails = {
top: 1.5,
left: 2.7,
bottom: 3.9,
right: 4.1
};
// WHEN creating from dictionary
const edgeInsets = IterableEdgeInsets.fromDict(dict);
// THEN it should have the decimal values
expect(edgeInsets.top).toBe(1.5);
expect(edgeInsets.left).toBe(2.7);
expect(edgeInsets.bottom).toBe(3.9);
expect(edgeInsets.right).toBe(4.1);
});
it('should create instance from dictionary with mixed positive and negative values', () => {
// GIVEN a dictionary with mixed values
const dict: IterableEdgeInsetDetails = {
top: 10,
left: -5,
bottom: 0,
right: 15
};
// WHEN creating from dictionary
const edgeInsets = IterableEdgeInsets.fromDict(dict);
// THEN it should have the mixed values
expect(edgeInsets.top).toBe(10);
expect(edgeInsets.left).toBe(-5);
expect(edgeInsets.bottom).toBe(0);
expect(edgeInsets.right).toBe(15);
});
});
describe('property access', () => {
it('should allow property modification', () => {
// GIVEN an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(10, 20, 30, 40);
// WHEN modifying properties
edgeInsets.top = 100;
edgeInsets.left = 200;
edgeInsets.bottom = 300;
edgeInsets.right = 400;
// THEN the properties should be updated
expect(edgeInsets.top).toBe(100);
expect(edgeInsets.left).toBe(200);
expect(edgeInsets.bottom).toBe(300);
expect(edgeInsets.right).toBe(400);
});
it('should maintain property independence', () => {
// GIVEN an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(10, 20, 30, 40);
// WHEN modifying one property
edgeInsets.top = 999;
// THEN other properties should remain unchanged
expect(edgeInsets.top).toBe(999);
expect(edgeInsets.left).toBe(20);
expect(edgeInsets.bottom).toBe(30);
expect(edgeInsets.right).toBe(40);
});
});
describe('edge cases', () => {
it('should handle NaN values', () => {
// GIVEN NaN values
const top = NaN;
const left = NaN;
const bottom = NaN;
const right = NaN;
// WHEN creating an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(top, left, bottom, right);
// THEN it should store NaN values
expect(edgeInsets.top).toBeNaN();
expect(edgeInsets.left).toBeNaN();
expect(edgeInsets.bottom).toBeNaN();
expect(edgeInsets.right).toBeNaN();
});
it('should handle Infinity values', () => {
// GIVEN Infinity values
const top = Infinity;
const left = -Infinity;
const bottom = Infinity;
const right = -Infinity;
// WHEN creating an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(top, left, bottom, right);
// THEN it should store Infinity values
expect(edgeInsets.top).toBe(Infinity);
expect(edgeInsets.left).toBe(-Infinity);
expect(edgeInsets.bottom).toBe(Infinity);
expect(edgeInsets.right).toBe(-Infinity);
});
it('should handle very small decimal values', () => {
// GIVEN very small decimal values
const top = 0.0001;
const left = 0.0002;
const bottom = 0.0003;
const right = 0.0004;
// WHEN creating an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(top, left, bottom, right);
// THEN it should store the small decimal values
expect(edgeInsets.top).toBe(0.0001);
expect(edgeInsets.left).toBe(0.0002);
expect(edgeInsets.bottom).toBe(0.0003);
expect(edgeInsets.right).toBe(0.0004);
});
});
describe('interface compliance', () => {
it('should implement IterableEdgeInsetDetails interface', () => {
// GIVEN an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(10, 20, 30, 40);
// THEN it should have all required properties
expect(edgeInsets).toHaveProperty('top');
expect(edgeInsets).toHaveProperty('left');
expect(edgeInsets).toHaveProperty('bottom');
expect(edgeInsets).toHaveProperty('right');
// AND all properties should be numbers
expect(typeof edgeInsets.top).toBe('number');
expect(typeof edgeInsets.left).toBe('number');
expect(typeof edgeInsets.bottom).toBe('number');
expect(typeof edgeInsets.right).toBe('number');
});
it('should be assignable to IterableEdgeInsetDetails', () => {
// GIVEN an IterableEdgeInsets instance
const edgeInsets = new IterableEdgeInsets(10, 20, 30, 40);
// WHEN assigning to IterableEdgeInsetDetails
const details: IterableEdgeInsetDetails = edgeInsets;
// THEN it should work without type errors
expect(details.top).toBe(10);
expect(details.left).toBe(20);
expect(details.bottom).toBe(30);
expect(details.right).toBe(40);
});
});
describe('fromDict with edge cases', () => {
it('should handle dictionary with NaN values', () => {
// GIVEN a dictionary with NaN values
const dict: IterableEdgeInsetDetails = {
top: NaN,
left: NaN,
bottom: NaN,
right: NaN
};
// WHEN creating from dictionary
const edgeInsets = IterableEdgeInsets.fromDict(dict);
// THEN it should have NaN values
expect(edgeInsets.top).toBeNaN();
expect(edgeInsets.left).toBeNaN();
expect(edgeInsets.bottom).toBeNaN();
expect(edgeInsets.right).toBeNaN();
});
it('should handle dictionary with Infinity values', () => {
// GIVEN a dictionary with Infinity values
const dict: IterableEdgeInsetDetails = {
top: Infinity,
left: -Infinity,
bottom: Infinity,
right: -Infinity
};
// WHEN creating from dictionary
const edgeInsets = IterableEdgeInsets.fromDict(dict);
// THEN it should have Infinity values
expect(edgeInsets.top).toBe(Infinity);
expect(edgeInsets.left).toBe(-Infinity);
expect(edgeInsets.bottom).toBe(Infinity);
expect(edgeInsets.right).toBe(-Infinity);
});
});
});