@nestia/e2e 0.1.1 → 0.1.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.
@@ -1,69 +1,69 @@
1
- /**
2
- * Gaff comparator.
3
- *
4
- * `GaffComparator` is a set of comparator functions for `Array.sort()` function,
5
- * which can be used with {@link TestValidator.sort} function. If you want to see
6
- * how to use them, see the below example link.
7
- *
8
- * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
9
- * @author Jeongho Nam - https://github.com/samchon
10
- */
11
- export namespace GaffComparator {
12
- /**
13
- * String(s) comparator.
14
- *
15
- * @param getter Getter of string(s) from input
16
- * @returns Comparator function
17
- */
18
- export const strings =
19
- <T>(getter: (input: T) => string | string[]) =>
20
- (x: T, y: T) => {
21
- const a: string[] = wrap(getter(x));
22
- const b: string[] = wrap(getter(y));
23
-
24
- const idx: number = a.findIndex((v, i) => v !== b[i]);
25
- return idx !== -1 ? compare(a[idx], b[idx]) : 0;
26
- };
27
-
28
- /**
29
- * Date(s) comparator.
30
- *
31
- * @param getter Getter of date(s) from input
32
- * @returns Comparator function
33
- */
34
- export const dates =
35
- <T>(getter: (input: T) => string | string[]) =>
36
- (x: T, y: T) => {
37
- const take = (v: T) =>
38
- wrap(getter(v)).map((str) => new Date(str).getTime());
39
- const a: number[] = take(x);
40
- const b: number[] = take(y);
41
-
42
- const idx: number = a.findIndex((v, i) => v !== b[i]);
43
- return idx !== -1 ? a[idx] - b[idx] : 0;
44
- };
45
-
46
- /**
47
- * Number(s) comparator.
48
- *
49
- * @param closure Getter of number(s) from input
50
- * @returns Comparator function
51
- */
52
- export const numbers =
53
- <T>(closure: (input: T) => number | number[]) =>
54
- (x: T, y: T) => {
55
- const a: number[] = wrap(closure(x));
56
- const b: number[] = wrap(closure(y));
57
-
58
- const idx: number = a.findIndex((v, i) => v !== b[i]);
59
- return idx !== -1 ? a[idx] - b[idx] : 0;
60
- };
61
-
62
- function compare(x: string, y: string) {
63
- return x.localeCompare(y);
64
- }
65
-
66
- function wrap<T>(elem: T | T[]): T[] {
67
- return Array.isArray(elem) ? elem : [elem];
68
- }
69
- }
1
+ /**
2
+ * Gaff comparator.
3
+ *
4
+ * `GaffComparator` is a set of comparator functions for `Array.sort()` function,
5
+ * which can be used with {@link TestValidator.sort} function. If you want to see
6
+ * how to use them, see the below example link.
7
+ *
8
+ * @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
9
+ * @author Jeongho Nam - https://github.com/samchon
10
+ */
11
+ export namespace GaffComparator {
12
+ /**
13
+ * String(s) comparator.
14
+ *
15
+ * @param getter Getter of string(s) from input
16
+ * @returns Comparator function
17
+ */
18
+ export const strings =
19
+ <T>(getter: (input: T) => string | string[]) =>
20
+ (x: T, y: T) => {
21
+ const a: string[] = wrap(getter(x));
22
+ const b: string[] = wrap(getter(y));
23
+
24
+ const idx: number = a.findIndex((v, i) => v !== b[i]);
25
+ return idx !== -1 ? compare(a[idx], b[idx]) : 0;
26
+ };
27
+
28
+ /**
29
+ * Date(s) comparator.
30
+ *
31
+ * @param getter Getter of date(s) from input
32
+ * @returns Comparator function
33
+ */
34
+ export const dates =
35
+ <T>(getter: (input: T) => string | string[]) =>
36
+ (x: T, y: T) => {
37
+ const take = (v: T) =>
38
+ wrap(getter(v)).map((str) => new Date(str).getTime());
39
+ const a: number[] = take(x);
40
+ const b: number[] = take(y);
41
+
42
+ const idx: number = a.findIndex((v, i) => v !== b[i]);
43
+ return idx !== -1 ? a[idx] - b[idx] : 0;
44
+ };
45
+
46
+ /**
47
+ * Number(s) comparator.
48
+ *
49
+ * @param closure Getter of number(s) from input
50
+ * @returns Comparator function
51
+ */
52
+ export const numbers =
53
+ <T>(closure: (input: T) => number | number[]) =>
54
+ (x: T, y: T) => {
55
+ const a: number[] = wrap(closure(x));
56
+ const b: number[] = wrap(closure(y));
57
+
58
+ const idx: number = a.findIndex((v, i) => v !== b[i]);
59
+ return idx !== -1 ? a[idx] - b[idx] : 0;
60
+ };
61
+
62
+ function compare(x: string, y: string) {
63
+ return x.localeCompare(y);
64
+ }
65
+
66
+ function wrap<T>(elem: T | T[]): T[] {
67
+ return Array.isArray(elem) ? elem : [elem];
68
+ }
69
+ }
@@ -1,178 +1,178 @@
1
- import { back_inserter, randint } from "tstl";
2
- import { sample as _Sample } from "tstl/ranges";
3
-
4
- /**
5
- * Random data generator.
6
- *
7
- * @author Jeongho Nam - https://github.com/samchon
8
- */
9
- export namespace RandomGenerator {
10
- /* ----------------------------------------------------------------
11
- IDENTIFICATIONS
12
- ---------------------------------------------------------------- */
13
- const CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
14
- const LETTERS: string = "0123456789" + CHARACTERS;
15
-
16
- /**
17
- * Generate random alphabets
18
- *
19
- * @param length Length of alphabets
20
- * @returns Generated alphabets
21
- */
22
- export function alphabets(length: number): string {
23
- return new Array(length)
24
- .fill("")
25
- .map(() => CHARACTERS[randint(0, CHARACTERS.length - 1)])
26
- .join("");
27
- }
28
-
29
- /**
30
- * Generate random alpha-numeric characters.
31
- *
32
- * Generate random string constructed with only alphabets and numbers.
33
- *
34
- * @param length Length of characters
35
- * @returns Generated string
36
- */
37
- export function alphaNumeric(length: number): string {
38
- return new Array(length)
39
- .fill("")
40
- .map(() => LETTERS[randint(0, LETTERS.length - 1)])
41
- .join("");
42
- }
43
-
44
- /**
45
- * Generate random name.
46
- *
47
- * @param length Length of paragraph, default is 2 or 3
48
- * @returns Generated name
49
- */
50
- export function name(length: number = randint(2, 3)): string {
51
- return paragraph(length)();
52
- }
53
-
54
- /**
55
- * Generate random paragraph.
56
- *
57
- * @param sentences Number of sentences
58
- * @returns Paragraph generator
59
- */
60
- export const paragraph =
61
- (sentences: number = randint(2, 5)) =>
62
- /**
63
- * @param wordMin Minimum number of characters in a sentence
64
- * @param wordMax Maximum number of characters in a sentence
65
- * @returns Generated paragraph
66
- */
67
- (wordMin: number = 3, wordMax: number = 7): string =>
68
- new Array(sentences)
69
- .fill("")
70
- .map(() => alphabets(randint(wordMin, wordMax)))
71
- .join(" ");
72
-
73
- /**
74
- * Generate random content.
75
- *
76
- * @param paragraphes Number of paragraphes
77
- * @returns Currying function
78
- */
79
- export const content =
80
- (paragraphes: number = randint(3, 8)) =>
81
- /**
82
- * @param sentenceMin Minimum number of sentences in a paragraph
83
- * @param sentenceMax Maximum number of sentences in a paragraph
84
- * @returns Currying function
85
- */
86
- (sentenceMin: number = 10, sentenceMax: number = 40) =>
87
- /**
88
- * @param wordMin Minimum number of characters in a sentence
89
- * @param wordMax Maximum number of characters in a sentence
90
- * @returns Content generator
91
- */
92
- (wordMin: number = 1, wordMax: number = 7): string =>
93
- new Array(paragraphes)
94
- .fill("")
95
- .map(() =>
96
- paragraph(randint(sentenceMin, sentenceMax))(
97
- wordMin,
98
- wordMax,
99
- ),
100
- )
101
- .join("\n\n");
102
-
103
- /**
104
- * Generate random substring.
105
- *
106
- * @param content Target content
107
- * @returns Random substring
108
- */
109
- export function substring(content: string): string {
110
- const first: number = randint(0, content.length - 1);
111
- const last: number = randint(first + 1, content.length);
112
-
113
- return content.substring(first, last).trim();
114
- }
115
-
116
- /**
117
- * Generate random mobile number.
118
- *
119
- * @param prefix Prefix string, default is "010"
120
- * @returns Random mobile number
121
- */
122
- export function mobile(prefix: string = "010"): string {
123
- return `${prefix}${digit(3, 4)}${digit(4, 4)}`;
124
- }
125
-
126
- /**
127
- * Generate random digit.
128
- *
129
- * Generate random digit that filling front with zero characters
130
- * when value is less than maximum cipher.
131
- *
132
- * @param minC Minimum cipher
133
- * @param maxC Maximum cipher
134
- * @returns
135
- */
136
- export function digit(minC: number, maxC: number): string {
137
- const val: number = randint(0, Math.pow(10.0, maxC) - 1);
138
- const log10: number = val ? Math.floor(Math.log10(val)) + 1 : 0;
139
- const prefix: string = "0".repeat(Math.max(0, minC - log10));
140
-
141
- return prefix + val.toString();
142
- }
143
-
144
- /**
145
- * Generate random date.
146
- *
147
- * @param from Start date
148
- * @param range Range of random milliseconds
149
- * @returns Random date
150
- */
151
- export function date(from: Date, range: number): Date {
152
- const time: number = from.getTime() + randint(0, range);
153
- return new Date(time);
154
- }
155
-
156
- /**
157
- * Pick random elements from an array.
158
- *
159
- * @param array Target array
160
- * @param count Number of count to pick
161
- * @returns Sampled array
162
- */
163
- export function sample<T>(array: T[], count: number): T[] {
164
- const ret: T[] = [];
165
- _Sample(array, back_inserter(ret), count);
166
- return ret;
167
- }
168
-
169
- /**
170
- * Pick random element from an array.
171
- *
172
- * @param array Target array
173
- * @returns picked element
174
- */
175
- export function pick<T>(array: T[]): T {
176
- return array[randint(0, array.length - 1)];
177
- }
178
- }
1
+ import { back_inserter, randint } from "tstl";
2
+ import { sample as _Sample } from "tstl/ranges";
3
+
4
+ /**
5
+ * Random data generator.
6
+ *
7
+ * @author Jeongho Nam - https://github.com/samchon
8
+ */
9
+ export namespace RandomGenerator {
10
+ /* ----------------------------------------------------------------
11
+ IDENTIFICATIONS
12
+ ---------------------------------------------------------------- */
13
+ const CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
14
+ const LETTERS: string = "0123456789" + CHARACTERS;
15
+
16
+ /**
17
+ * Generate random alphabets
18
+ *
19
+ * @param length Length of alphabets
20
+ * @returns Generated alphabets
21
+ */
22
+ export function alphabets(length: number): string {
23
+ return new Array(length)
24
+ .fill("")
25
+ .map(() => CHARACTERS[randint(0, CHARACTERS.length - 1)])
26
+ .join("");
27
+ }
28
+
29
+ /**
30
+ * Generate random alpha-numeric characters.
31
+ *
32
+ * Generate random string constructed with only alphabets and numbers.
33
+ *
34
+ * @param length Length of characters
35
+ * @returns Generated string
36
+ */
37
+ export function alphaNumeric(length: number): string {
38
+ return new Array(length)
39
+ .fill("")
40
+ .map(() => LETTERS[randint(0, LETTERS.length - 1)])
41
+ .join("");
42
+ }
43
+
44
+ /**
45
+ * Generate random name.
46
+ *
47
+ * @param length Length of paragraph, default is 2 or 3
48
+ * @returns Generated name
49
+ */
50
+ export function name(length: number = randint(2, 3)): string {
51
+ return paragraph(length)();
52
+ }
53
+
54
+ /**
55
+ * Generate random paragraph.
56
+ *
57
+ * @param sentences Number of sentences
58
+ * @returns Paragraph generator
59
+ */
60
+ export const paragraph =
61
+ (sentences: number = randint(2, 5)) =>
62
+ /**
63
+ * @param wordMin Minimum number of characters in a sentence
64
+ * @param wordMax Maximum number of characters in a sentence
65
+ * @returns Generated paragraph
66
+ */
67
+ (wordMin: number = 3, wordMax: number = 7): string =>
68
+ new Array(sentences)
69
+ .fill("")
70
+ .map(() => alphabets(randint(wordMin, wordMax)))
71
+ .join(" ");
72
+
73
+ /**
74
+ * Generate random content.
75
+ *
76
+ * @param paragraphes Number of paragraphes
77
+ * @returns Currying function
78
+ */
79
+ export const content =
80
+ (paragraphes: number = randint(3, 8)) =>
81
+ /**
82
+ * @param sentenceMin Minimum number of sentences in a paragraph
83
+ * @param sentenceMax Maximum number of sentences in a paragraph
84
+ * @returns Currying function
85
+ */
86
+ (sentenceMin: number = 10, sentenceMax: number = 40) =>
87
+ /**
88
+ * @param wordMin Minimum number of characters in a sentence
89
+ * @param wordMax Maximum number of characters in a sentence
90
+ * @returns Content generator
91
+ */
92
+ (wordMin: number = 1, wordMax: number = 7): string =>
93
+ new Array(paragraphes)
94
+ .fill("")
95
+ .map(() =>
96
+ paragraph(randint(sentenceMin, sentenceMax))(
97
+ wordMin,
98
+ wordMax,
99
+ ),
100
+ )
101
+ .join("\n\n");
102
+
103
+ /**
104
+ * Generate random substring.
105
+ *
106
+ * @param content Target content
107
+ * @returns Random substring
108
+ */
109
+ export function substring(content: string): string {
110
+ const first: number = randint(0, content.length - 1);
111
+ const last: number = randint(first + 1, content.length);
112
+
113
+ return content.substring(first, last).trim();
114
+ }
115
+
116
+ /**
117
+ * Generate random mobile number.
118
+ *
119
+ * @param prefix Prefix string, default is "010"
120
+ * @returns Random mobile number
121
+ */
122
+ export function mobile(prefix: string = "010"): string {
123
+ return `${prefix}${digit(3, 4)}${digit(4, 4)}`;
124
+ }
125
+
126
+ /**
127
+ * Generate random digit.
128
+ *
129
+ * Generate random digit that filling front with zero characters
130
+ * when value is less than maximum cipher.
131
+ *
132
+ * @param minC Minimum cipher
133
+ * @param maxC Maximum cipher
134
+ * @returns
135
+ */
136
+ export function digit(minC: number, maxC: number): string {
137
+ const val: number = randint(0, Math.pow(10.0, maxC) - 1);
138
+ const log10: number = val ? Math.floor(Math.log10(val)) + 1 : 0;
139
+ const prefix: string = "0".repeat(Math.max(0, minC - log10));
140
+
141
+ return prefix + val.toString();
142
+ }
143
+
144
+ /**
145
+ * Generate random date.
146
+ *
147
+ * @param from Start date
148
+ * @param range Range of random milliseconds
149
+ * @returns Random date
150
+ */
151
+ export function date(from: Date, range: number): Date {
152
+ const time: number = from.getTime() + randint(0, range);
153
+ return new Date(time);
154
+ }
155
+
156
+ /**
157
+ * Pick random elements from an array.
158
+ *
159
+ * @param array Target array
160
+ * @param count Number of count to pick
161
+ * @returns Sampled array
162
+ */
163
+ export function sample<T>(array: T[], count: number): T[] {
164
+ const ret: T[] = [];
165
+ _Sample(array, back_inserter(ret), count);
166
+ return ret;
167
+ }
168
+
169
+ /**
170
+ * Pick random element from an array.
171
+ *
172
+ * @param array Target array
173
+ * @returns picked element
174
+ */
175
+ export function pick<T>(array: T[]): T {
176
+ return array[randint(0, array.length - 1)];
177
+ }
178
+ }
package/src/StopWatch.ts CHANGED
@@ -1,36 +1,36 @@
1
- /**
2
- * Elapsed time measurement utility.
3
- *
4
- * @author Sachon
5
- */
6
- export namespace StopWatch {
7
- /**
8
- * Type of task.
9
- */
10
- export type Task = () => Promise<void>;
11
-
12
- /**
13
- *
14
- * @param task
15
- * @returns
16
- */
17
- export async function measure(task: Task): Promise<number> {
18
- const time: number = Date.now();
19
- await task();
20
- return Date.now() - time;
21
- }
22
-
23
- /**
24
- *
25
- * @param title
26
- * @param task
27
- * @returns
28
- */
29
- export async function trace(title: string, task: Task): Promise<number> {
30
- process.stdout.write(` - ${title}: `);
31
- const time: number = await measure(task);
32
-
33
- console.log(`${time.toLocaleString()} ms`);
34
- return time;
35
- }
36
- }
1
+ /**
2
+ * Elapsed time measurement utility.
3
+ *
4
+ * @author Sachon
5
+ */
6
+ export namespace StopWatch {
7
+ /**
8
+ * Type of task.
9
+ */
10
+ export type Task = () => Promise<void>;
11
+
12
+ /**
13
+ *
14
+ * @param task
15
+ * @returns
16
+ */
17
+ export async function measure(task: Task): Promise<number> {
18
+ const time: number = Date.now();
19
+ await task();
20
+ return Date.now() - time;
21
+ }
22
+
23
+ /**
24
+ *
25
+ * @param title
26
+ * @param task
27
+ * @returns
28
+ */
29
+ export async function trace(title: string, task: Task): Promise<number> {
30
+ process.stdout.write(` - ${title}: `);
31
+ const time: number = await measure(task);
32
+
33
+ console.log(`${time.toLocaleString()} ms`);
34
+ return time;
35
+ }
36
+ }