@nestia/e2e 7.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/lib/ArrayUtil.d.ts +227 -2
- package/lib/ArrayUtil.js +227 -30
- package/lib/ArrayUtil.js.map +1 -1
- package/lib/GaffComparator.d.ts +229 -14
- package/lib/GaffComparator.js +229 -14
- package/lib/GaffComparator.js.map +1 -1
- package/lib/RandomGenerator.d.ts +332 -35
- package/lib/RandomGenerator.js +337 -50
- package/lib/RandomGenerator.js.map +1 -1
- package/lib/TestValidator.d.ts +334 -35
- package/lib/TestValidator.js +267 -57
- package/lib/TestValidator.js.map +1 -1
- package/lib/internal/json_equal_to.d.ts +1 -1
- package/lib/internal/json_equal_to.js.map +1 -1
- package/package.json +1 -1
- package/src/ArrayUtil.ts +227 -3
- package/src/GaffComparator.ts +230 -14
- package/src/RandomGenerator.ts +339 -50
- package/src/TestValidator.ts +351 -58
- package/src/internal/json_equal_to.ts +1 -1
package/lib/RandomGenerator.js
CHANGED
|
@@ -2,22 +2,72 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RandomGenerator = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Comprehensive random data generation utilities for testing and development.
|
|
6
|
+
*
|
|
7
|
+
* RandomGenerator provides a collection of functions for generating random data
|
|
8
|
+
* including strings, names, content, dates, and array sampling. All functions
|
|
9
|
+
* are designed to be deterministic within a single execution but produce varied
|
|
10
|
+
* output across different runs, making them ideal for testing scenarios.
|
|
11
|
+
*
|
|
12
|
+
* The namespace includes specialized generators for:
|
|
13
|
+
*
|
|
14
|
+
* - Text content (alphabets, alphanumeric, names, paragraphs)
|
|
15
|
+
* - Phone numbers and contact information
|
|
16
|
+
* - Date ranges and time-based data
|
|
17
|
+
* - Array sampling and element selection
|
|
6
18
|
*
|
|
7
19
|
* @author Jeongho Nam - https://github.com/samchon
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Generate test user data
|
|
23
|
+
* const testUser = {
|
|
24
|
+
* id: RandomGenerator.alphaNumeric(8),
|
|
25
|
+
* name: RandomGenerator.name(),
|
|
26
|
+
* bio: RandomGenerator.paragraph(3)(5, 10),
|
|
27
|
+
* phone: RandomGenerator.mobile(),
|
|
28
|
+
* createdAt: RandomGenerator.date(new Date())(1000 * 60 * 60 * 24 * 30) // 30 days
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* // Sample data for testing
|
|
32
|
+
* const testSample = RandomGenerator.sample(allUsers)(5);
|
|
33
|
+
* ```;
|
|
8
34
|
*/
|
|
9
35
|
var RandomGenerator;
|
|
10
36
|
(function (RandomGenerator) {
|
|
11
37
|
/* ----------------------------------------------------------------
|
|
12
38
|
IDENTIFICATIONS
|
|
13
39
|
---------------------------------------------------------------- */
|
|
40
|
+
/** Character set containing lowercase alphabetical characters a-z */
|
|
14
41
|
var CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
42
|
+
/**
|
|
43
|
+
* Character set containing digits (0-9) and lowercase alphabetical characters
|
|
44
|
+
* (a-z)
|
|
45
|
+
*/
|
|
15
46
|
var LETTERS = "0123456789" + CHARACTERS;
|
|
16
47
|
/**
|
|
17
|
-
*
|
|
48
|
+
* Generates a random string containing only lowercase alphabetical
|
|
49
|
+
* characters.
|
|
50
|
+
*
|
|
51
|
+
* Creates a string of specified length using only characters a-z. Each
|
|
52
|
+
* character is independently randomly selected, so the same character may
|
|
53
|
+
* appear multiple times. Useful for generating random identifiers, test
|
|
54
|
+
* names, or placeholder text.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* RandomGenerator.alphabets(5); // "hello"
|
|
59
|
+
* RandomGenerator.alphabets(3); // "abc"
|
|
60
|
+
* RandomGenerator.alphabets(10); // "randomtext"
|
|
18
61
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
62
|
+
* // Generate random CSS class names
|
|
63
|
+
* const className = `test-${RandomGenerator.alphabets(6)}`;
|
|
64
|
+
*
|
|
65
|
+
* // Create random variable names for testing
|
|
66
|
+
* const varName = RandomGenerator.alphabets(8);
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param length - The desired length of the generated alphabetic string
|
|
70
|
+
* @returns A string containing only lowercase letters of the specified length
|
|
21
71
|
*/
|
|
22
72
|
RandomGenerator.alphabets = function (length) {
|
|
23
73
|
return new Array(length)
|
|
@@ -26,12 +76,32 @@ var RandomGenerator;
|
|
|
26
76
|
.join("");
|
|
27
77
|
};
|
|
28
78
|
/**
|
|
29
|
-
*
|
|
79
|
+
* Generates a random alphanumeric string containing digits and lowercase
|
|
80
|
+
* letters.
|
|
81
|
+
*
|
|
82
|
+
* Creates a string of specified length using characters from 0-9 and a-z.
|
|
83
|
+
* Each position is independently randomly selected from the combined
|
|
84
|
+
* character set. Ideal for generating random IDs, tokens, passwords, or
|
|
85
|
+
* unique identifiers that need both numeric and alphabetic characters.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* RandomGenerator.alphaNumeric(8); // "a1b2c3d4"
|
|
90
|
+
* RandomGenerator.alphaNumeric(12); // "x9y8z7w6v5u4"
|
|
30
91
|
*
|
|
31
|
-
* Generate random
|
|
92
|
+
* // Generate random API keys
|
|
93
|
+
* const apiKey = RandomGenerator.alphaNumeric(32);
|
|
32
94
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
95
|
+
* // Create session tokens
|
|
96
|
+
* const sessionId = `sess_${RandomGenerator.alphaNumeric(16)}`;
|
|
97
|
+
*
|
|
98
|
+
* // Generate test database IDs
|
|
99
|
+
* const testId = RandomGenerator.alphaNumeric(10);
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @param length - The desired length of the generated alphanumeric string
|
|
103
|
+
* @returns A string containing digits and lowercase letters of the specified
|
|
104
|
+
* length
|
|
35
105
|
*/
|
|
36
106
|
RandomGenerator.alphaNumeric = function (length) {
|
|
37
107
|
return new Array(length)
|
|
@@ -40,28 +110,73 @@ var RandomGenerator;
|
|
|
40
110
|
.join("");
|
|
41
111
|
};
|
|
42
112
|
/**
|
|
43
|
-
*
|
|
113
|
+
* Generates a random name-like string with realistic length variation.
|
|
114
|
+
*
|
|
115
|
+
* Creates a name by generating a paragraph with 2-3 words (randomly chosen).
|
|
116
|
+
* The resulting string resembles typical human names in structure and length.
|
|
117
|
+
* Each word is between 3-7 characters by default, creating realistic-looking
|
|
118
|
+
* names.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* RandomGenerator.name(); // "john doe"
|
|
123
|
+
* RandomGenerator.name(1); // "alice"
|
|
124
|
+
* RandomGenerator.name(3); // "jane mary smith"
|
|
44
125
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
126
|
+
* // Generate test user names
|
|
127
|
+
* const users = Array.from({ length: 10 }, () => ({
|
|
128
|
+
* id: RandomGenerator.alphaNumeric(8),
|
|
129
|
+
* name: RandomGenerator.name(),
|
|
130
|
+
* email: `${RandomGenerator.name(1)}@test.com`
|
|
131
|
+
* }));
|
|
132
|
+
*
|
|
133
|
+
* // Create random author names for blog posts
|
|
134
|
+
* const authorName = RandomGenerator.name();
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @param length - Number of words in the name (default: random between 2-3)
|
|
138
|
+
* @returns A space-separated string resembling a human name
|
|
47
139
|
*/
|
|
48
140
|
RandomGenerator.name = function (length) {
|
|
49
141
|
if (length === void 0) { length = randint(2, 3); }
|
|
50
142
|
return RandomGenerator.paragraph(length)();
|
|
51
143
|
};
|
|
52
144
|
/**
|
|
53
|
-
*
|
|
145
|
+
* Generates a random paragraph with configurable sentence structure.
|
|
146
|
+
*
|
|
147
|
+
* Creates a paragraph consisting of a specified number of "sentences"
|
|
148
|
+
* (words). Each sentence is a random alphabetic string, and sentences are
|
|
149
|
+
* joined with spaces. Returns a currying function to allow configuration of
|
|
150
|
+
* word length ranges.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* // Generate with default word lengths (3-7 characters)
|
|
155
|
+
* RandomGenerator.paragraph(3)(); // "hello world test"
|
|
156
|
+
* RandomGenerator.paragraph(5)(); // "lorem ipsum dolor sit amet"
|
|
157
|
+
*
|
|
158
|
+
* // Custom word length ranges
|
|
159
|
+
* RandomGenerator.paragraph(4)(2, 5); // "ab cd ef gh"
|
|
160
|
+
* RandomGenerator.paragraph(6)(8, 12); // "verylongword anotherlongword..."
|
|
161
|
+
*
|
|
162
|
+
* // Generate product descriptions
|
|
163
|
+
* const description = RandomGenerator.paragraph(8)(4, 8);
|
|
164
|
+
*
|
|
165
|
+
* // Create test content for forms
|
|
166
|
+
* const placeholder = RandomGenerator.paragraph(3)(5, 10);
|
|
167
|
+
*
|
|
168
|
+
* // Generate variable-length test data
|
|
169
|
+
* const testTexts = Array.from({ length: 5 }, (_, i) =>
|
|
170
|
+
* RandomGenerator.paragraph(i + 2)(3, 6)
|
|
171
|
+
* );
|
|
172
|
+
* ```;
|
|
54
173
|
*
|
|
55
|
-
* @param sentences Number of sentences
|
|
56
|
-
*
|
|
174
|
+
* @param sentences - Number of sentences (words) in the paragraph (default:
|
|
175
|
+
* random 2-5)
|
|
176
|
+
* @returns A currying function that accepts word length parameters
|
|
57
177
|
*/
|
|
58
178
|
RandomGenerator.paragraph = function (sentences) {
|
|
59
179
|
if (sentences === void 0) { sentences = randint(2, 5); }
|
|
60
|
-
/**
|
|
61
|
-
* @param wordMin Minimum number of characters in a sentence
|
|
62
|
-
* @param wordMax Maximum number of characters in a sentence
|
|
63
|
-
* @returns Generated paragraph
|
|
64
|
-
*/
|
|
65
180
|
return function (wordMin, wordMax) {
|
|
66
181
|
if (wordMin === void 0) { wordMin = 3; }
|
|
67
182
|
if (wordMax === void 0) { wordMax = 7; }
|
|
@@ -72,26 +187,50 @@ var RandomGenerator;
|
|
|
72
187
|
};
|
|
73
188
|
};
|
|
74
189
|
/**
|
|
75
|
-
*
|
|
190
|
+
* Generates random multi-paragraph content with customizable structure.
|
|
76
191
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
192
|
+
* Creates content consisting of multiple paragraphs separated by double
|
|
193
|
+
* newlines. Uses a triple-currying pattern to allow fine-grained control over
|
|
194
|
+
* content structure: paragraphs count → sentences per paragraph → word
|
|
195
|
+
* character lengths. Ideal for generating realistic-looking text content for
|
|
196
|
+
* testing.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* // Generate with all defaults
|
|
201
|
+
* const article = RandomGenerator.content()()();
|
|
202
|
+
*
|
|
203
|
+
* // Specific structure: 5 paragraphs, 15-25 sentences each, 4-8 char words
|
|
204
|
+
* const longContent = RandomGenerator.content(5)(15, 25)(4, 8);
|
|
205
|
+
*
|
|
206
|
+
* // Short content with brief sentences
|
|
207
|
+
* const shortContent = RandomGenerator.content(2)(5, 8)(2, 4);
|
|
208
|
+
*
|
|
209
|
+
* // Generate blog post content
|
|
210
|
+
* const blogPost = {
|
|
211
|
+
* title: RandomGenerator.name(3),
|
|
212
|
+
* content: RandomGenerator.content(4)(10, 20)(3, 7),
|
|
213
|
+
* summary: RandomGenerator.paragraph(2)(5, 10)
|
|
214
|
+
* };
|
|
215
|
+
*
|
|
216
|
+
* // Create test data for CMS
|
|
217
|
+
* const pages = Array.from({ length: 10 }, () => ({
|
|
218
|
+
* id: RandomGenerator.alphaNumeric(8),
|
|
219
|
+
* content: RandomGenerator.content(randint(2, 6))(8, 15)(4, 9)
|
|
220
|
+
* }));
|
|
221
|
+
*
|
|
222
|
+
* // Generate email content for testing
|
|
223
|
+
* const emailBody = RandomGenerator.content(3)(5, 12)(3, 8);
|
|
224
|
+
* ```;
|
|
225
|
+
*
|
|
226
|
+
* @param paragraphs - Number of paragraphs to generate (default: random 3-8)
|
|
227
|
+
* @returns A currying function that accepts sentence count parameters
|
|
79
228
|
*/
|
|
80
229
|
RandomGenerator.content = function (paragraphs) {
|
|
81
230
|
if (paragraphs === void 0) { paragraphs = randint(3, 8); }
|
|
82
|
-
/**
|
|
83
|
-
* @param sentenceMin Minimum number of sentences in a paragraph
|
|
84
|
-
* @param sentenceMax Maximum number of sentences in a paragraph
|
|
85
|
-
* @returns Currying function
|
|
86
|
-
*/
|
|
87
231
|
return function (sentenceMin, sentenceMax) {
|
|
88
232
|
if (sentenceMin === void 0) { sentenceMin = 10; }
|
|
89
233
|
if (sentenceMax === void 0) { sentenceMax = 40; }
|
|
90
|
-
/**
|
|
91
|
-
* @param wordMin Minimum number of characters in a sentence
|
|
92
|
-
* @param wordMax Maximum number of characters in a sentence
|
|
93
|
-
* @returns Content generator
|
|
94
|
-
*/
|
|
95
234
|
return function (wordMin, wordMax) {
|
|
96
235
|
if (wordMin === void 0) { wordMin = 1; }
|
|
97
236
|
if (wordMax === void 0) { wordMax = 7; }
|
|
@@ -105,10 +244,36 @@ var RandomGenerator;
|
|
|
105
244
|
};
|
|
106
245
|
};
|
|
107
246
|
/**
|
|
108
|
-
*
|
|
247
|
+
* Extracts a random substring from the provided content string.
|
|
248
|
+
*
|
|
249
|
+
* Selects two random positions within the content and returns the substring
|
|
250
|
+
* between them. The starting position is always before the ending position.
|
|
251
|
+
* Automatically trims whitespace from the beginning and end of the result.
|
|
252
|
+
* Useful for creating excerpts, search terms, or partial content samples.
|
|
109
253
|
*
|
|
110
|
-
* @
|
|
111
|
-
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const text = "The quick brown fox jumps over the lazy dog";
|
|
257
|
+
*
|
|
258
|
+
* RandomGenerator.substring(text); // "quick brown fox"
|
|
259
|
+
* RandomGenerator.substring(text); // "jumps over"
|
|
260
|
+
* RandomGenerator.substring(text); // "fox jumps over the lazy"
|
|
261
|
+
*
|
|
262
|
+
* // Generate search terms from content
|
|
263
|
+
* const searchQuery = RandomGenerator.substring(articleContent);
|
|
264
|
+
*
|
|
265
|
+
* // Create excerpts for previews
|
|
266
|
+
* const excerpt = RandomGenerator.substring(fullBlogPost);
|
|
267
|
+
*
|
|
268
|
+
* // Generate partial matches for testing search functionality
|
|
269
|
+
* const partialMatch = RandomGenerator.substring(productDescription);
|
|
270
|
+
*
|
|
271
|
+
* // Create random selections for highlight testing
|
|
272
|
+
* const selectedText = RandomGenerator.substring(documentContent);
|
|
273
|
+
* ```;
|
|
274
|
+
*
|
|
275
|
+
* @param content - The source string to extract a substring from
|
|
276
|
+
* @returns A trimmed substring of the original content
|
|
112
277
|
*/
|
|
113
278
|
RandomGenerator.substring = function (content) {
|
|
114
279
|
var first = randint(0, content.length - 1);
|
|
@@ -116,11 +281,39 @@ var RandomGenerator;
|
|
|
116
281
|
return content.substring(first, last).trim();
|
|
117
282
|
};
|
|
118
283
|
/**
|
|
119
|
-
*
|
|
284
|
+
* Generates a random mobile phone number with customizable prefix.
|
|
285
|
+
*
|
|
286
|
+
* Creates a mobile phone number in the format: [prefix][3-4 digits][4
|
|
287
|
+
* digits]. The middle section is 3 digits if the random number is less than
|
|
288
|
+
* 1000, otherwise 4 digits. The last section is always 4 digits, zero-padded
|
|
289
|
+
* if necessary. Commonly used for generating Korean mobile phone numbers or
|
|
290
|
+
* similar formats.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```typescript
|
|
294
|
+
* RandomGenerator.mobile(); // "0103341234"
|
|
295
|
+
* RandomGenerator.mobile("011"); // "0119876543"
|
|
296
|
+
* RandomGenerator.mobile("+82"); // "+8233412345"
|
|
120
297
|
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
298
|
+
* // Generate test user phone numbers
|
|
299
|
+
* const testUsers = Array.from({ length: 100 }, () => ({
|
|
300
|
+
* name: RandomGenerator.name(),
|
|
301
|
+
* phone: RandomGenerator.mobile(),
|
|
302
|
+
* altPhone: RandomGenerator.mobile("011")
|
|
303
|
+
* }));
|
|
304
|
+
*
|
|
305
|
+
* // Create international phone numbers
|
|
306
|
+
* const internationalPhone = RandomGenerator.mobile("+821");
|
|
307
|
+
*
|
|
308
|
+
* // Generate contact list for testing
|
|
309
|
+
* const contacts = ["010", "011", "016", "017", "018", "019"].map(prefix => ({
|
|
310
|
+
* carrier: prefix,
|
|
311
|
+
* number: RandomGenerator.mobile(prefix)
|
|
312
|
+
* }));
|
|
313
|
+
* ```;
|
|
314
|
+
*
|
|
315
|
+
* @param prefix - The prefix string for the phone number (default: "010")
|
|
316
|
+
* @returns A formatted mobile phone number string
|
|
124
317
|
*/
|
|
125
318
|
RandomGenerator.mobile = function (prefix) {
|
|
126
319
|
if (prefix === void 0) { prefix = "010"; }
|
|
@@ -134,11 +327,43 @@ var RandomGenerator;
|
|
|
134
327
|
].join("");
|
|
135
328
|
};
|
|
136
329
|
/**
|
|
137
|
-
*
|
|
330
|
+
* Generates a random date within a specified range from a starting point.
|
|
331
|
+
*
|
|
332
|
+
* Creates a currying function that accepts a range in milliseconds and
|
|
333
|
+
* returns a random date between the start date and start date + range. The
|
|
334
|
+
* range represents the maximum number of milliseconds to add to the starting
|
|
335
|
+
* date. Useful for generating timestamps, creation dates, or scheduling test
|
|
336
|
+
* data.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* const now = new Date();
|
|
341
|
+
* const oneDay = 24 * 60 * 60 * 1000;
|
|
342
|
+
* const oneMonth = 30 * oneDay;
|
|
343
|
+
*
|
|
344
|
+
* // Random date within the next 30 days
|
|
345
|
+
* const futureDate = RandomGenerator.date(now)(oneMonth);
|
|
346
|
+
*
|
|
347
|
+
* // Random date within the past week
|
|
348
|
+
* const pastWeek = new Date(now.getTime() - 7 * oneDay);
|
|
349
|
+
* const recentDate = RandomGenerator.date(pastWeek)(7 * oneDay);
|
|
350
|
+
*
|
|
351
|
+
* // Generate random creation dates for test data
|
|
352
|
+
* const startOfYear = new Date(2024, 0, 1);
|
|
353
|
+
* const endOfYear = new Date(2024, 11, 31).getTime() - startOfYear.getTime();
|
|
354
|
+
* const randomCreationDate = RandomGenerator.date(startOfYear)(endOfYear);
|
|
138
355
|
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
356
|
+
* // Create test events with random timestamps
|
|
357
|
+
* const events = Array.from({ length: 50 }, () => ({
|
|
358
|
+
* id: RandomGenerator.alphaNumeric(8),
|
|
359
|
+
* title: RandomGenerator.name(2),
|
|
360
|
+
* createdAt: RandomGenerator.date(new Date())(oneMonth),
|
|
361
|
+
* scheduledFor: RandomGenerator.date(new Date())(oneMonth * 3)
|
|
362
|
+
* }));
|
|
363
|
+
* ```;
|
|
364
|
+
*
|
|
365
|
+
* @param from - The starting date for the random range
|
|
366
|
+
* @returns A currying function that accepts a range in milliseconds
|
|
142
367
|
*/
|
|
143
368
|
RandomGenerator.date = function (from) {
|
|
144
369
|
return function (range) {
|
|
@@ -146,11 +371,40 @@ var RandomGenerator;
|
|
|
146
371
|
};
|
|
147
372
|
};
|
|
148
373
|
/**
|
|
149
|
-
*
|
|
374
|
+
* Randomly samples a specified number of unique elements from an array.
|
|
375
|
+
*
|
|
376
|
+
* Selects random elements from the input array without replacement, ensuring
|
|
377
|
+
* all returned elements are unique. The sample size is automatically capped
|
|
378
|
+
* at the array length to prevent errors. Uses a Set-based approach to
|
|
379
|
+
* guarantee uniqueness of selected indices. Ideal for creating test datasets
|
|
380
|
+
* or selecting random subsets for validation.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```typescript
|
|
384
|
+
* const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
385
|
+
*
|
|
386
|
+
* RandomGenerator.sample(numbers)(3); // [2, 7, 9]
|
|
387
|
+
* RandomGenerator.sample(numbers)(5); // [1, 4, 6, 8, 10]
|
|
388
|
+
* RandomGenerator.sample(numbers)(15); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (capped at array length)
|
|
389
|
+
*
|
|
390
|
+
* // Sample users for testing
|
|
391
|
+
* const allUsers = await getUsersFromDatabase();
|
|
392
|
+
* const testUsers = RandomGenerator.sample(allUsers)(10);
|
|
393
|
+
*
|
|
394
|
+
* // Create random product selections
|
|
395
|
+
* const featuredProducts = RandomGenerator.sample(allProducts)(5);
|
|
396
|
+
*
|
|
397
|
+
* // Generate test data subsets
|
|
398
|
+
* const validationSet = RandomGenerator.sample(trainingData)(100);
|
|
399
|
+
*
|
|
400
|
+
* // Random A/B testing groups
|
|
401
|
+
* const groupA = RandomGenerator.sample(allParticipants)(50);
|
|
402
|
+
* const remaining = allParticipants.filter(p => !groupA.includes(p));
|
|
403
|
+
* const groupB = RandomGenerator.sample(remaining)(50);
|
|
404
|
+
* ```;
|
|
150
405
|
*
|
|
151
|
-
* @param array
|
|
152
|
-
* @
|
|
153
|
-
* @returns Sampled array
|
|
406
|
+
* @param array - The source array to sample from
|
|
407
|
+
* @returns A currying function that accepts the desired sample count
|
|
154
408
|
*/
|
|
155
409
|
RandomGenerator.sample = function (array) {
|
|
156
410
|
return function (count) {
|
|
@@ -162,10 +416,43 @@ var RandomGenerator;
|
|
|
162
416
|
};
|
|
163
417
|
};
|
|
164
418
|
/**
|
|
165
|
-
*
|
|
419
|
+
* Randomly selects a single element from an array.
|
|
420
|
+
*
|
|
421
|
+
* Chooses one element at random from the provided array using uniform
|
|
422
|
+
* distribution. Each element has an equal probability of being selected. This
|
|
423
|
+
* is a convenience function equivalent to sampling with a count of 1, but
|
|
424
|
+
* returns the element directly rather than an array containing one element.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```typescript
|
|
428
|
+
* const colors = ['red', 'blue', 'green', 'yellow', 'purple'];
|
|
429
|
+
* const fruits = ['apple', 'banana', 'orange', 'grape', 'kiwi'];
|
|
430
|
+
*
|
|
431
|
+
* RandomGenerator.pick(colors); // "blue"
|
|
432
|
+
* RandomGenerator.pick(fruits); // "apple"
|
|
433
|
+
*
|
|
434
|
+
* // Select random configuration options
|
|
435
|
+
* const randomTheme = RandomGenerator.pick(['light', 'dark', 'auto']);
|
|
436
|
+
* const randomLocale = RandomGenerator.pick(['en', 'ko', 'ja', 'zh']);
|
|
437
|
+
*
|
|
438
|
+
* // Choose random test scenarios
|
|
439
|
+
* const testScenario = RandomGenerator.pick([
|
|
440
|
+
* 'happy_path',
|
|
441
|
+
* 'edge_case',
|
|
442
|
+
* 'error_condition',
|
|
443
|
+
* 'boundary_test'
|
|
444
|
+
* ]);
|
|
445
|
+
*
|
|
446
|
+
* // Random user role assignment
|
|
447
|
+
* const userRole = RandomGenerator.pick(['admin', 'user', 'moderator']);
|
|
448
|
+
*
|
|
449
|
+
* // Select random API endpoints for testing
|
|
450
|
+
* const endpoints = ['/users', '/posts', '/comments', '/categories'];
|
|
451
|
+
* const randomEndpoint = RandomGenerator.pick(endpoints);
|
|
452
|
+
* ```;
|
|
166
453
|
*
|
|
167
|
-
* @param array
|
|
168
|
-
* @returns
|
|
454
|
+
* @param array - The source array to pick an element from
|
|
455
|
+
* @returns A randomly selected element from the array
|
|
169
456
|
*/
|
|
170
457
|
RandomGenerator.pick = function (array) { return array[randint(0, array.length - 1)]; };
|
|
171
458
|
})(RandomGenerator || (exports.RandomGenerator = RandomGenerator = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RandomGenerator.js","sourceRoot":"","sources":["../src/RandomGenerator.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"RandomGenerator.js","sourceRoot":"","sources":["../src/RandomGenerator.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,IAAiB,eAAe,CAga/B;AAhaD,WAAiB,eAAe;IAC9B;;yEAEqE;IAErE,qEAAqE;IACrE,IAAM,UAAU,GAAG,4BAA4B,CAAC;IAEhD;;;OAGG;IACH,IAAM,OAAO,GAAW,YAAY,GAAG,UAAU,CAA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