@nestia/e2e 0.4.1 → 0.4.3

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,5 +1,5 @@
1
1
  import { back_inserter, randint } from "tstl";
2
- import { sample as _Sample } from "tstl/ranges";
2
+ import { ranges } from "tstl";
3
3
 
4
4
  /**
5
5
  * Random data generator.
@@ -147,7 +147,7 @@ export namespace RandomGenerator {
147
147
  <T>(array: T[]) =>
148
148
  (count: number): T[] => {
149
149
  const ret: T[] = [];
150
- _Sample(array, back_inserter(ret), count);
150
+ ranges.sample(array, back_inserter(ret), count);
151
151
  return ret;
152
152
  };
153
153
 
package/src/StopWatch.ts CHANGED
@@ -1,38 +1,38 @@
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<T> = () => Promise<T>;
11
-
12
- /**
13
- *
14
- * @param task
15
- * @returns
16
- */
17
- export const measure = async <T>(task: Task<T>): Promise<[T, number]> => {
18
- const time: number = Date.now();
19
- const output: T = await task();
20
- return [output, Date.now() - time];
21
- };
22
-
23
- /**
24
- *
25
- * @param title
26
- * @param task
27
- * @returns
28
- */
29
- export const trace =
30
- (title: string) =>
31
- async <T>(task: Task<T>): Promise<[T, number]> => {
32
- process.stdout.write(` - ${title}: `);
33
- const res: [T, number] = await measure(task);
34
-
35
- console.log(`${res[1].toLocaleString()} ms`);
36
- return res;
37
- };
38
- }
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<T> = () => Promise<T>;
11
+
12
+ /**
13
+ *
14
+ * @param task
15
+ * @returns
16
+ */
17
+ export const measure = async <T>(task: Task<T>): Promise<[T, number]> => {
18
+ const time: number = Date.now();
19
+ const output: T = await task();
20
+ return [output, Date.now() - time];
21
+ };
22
+
23
+ /**
24
+ *
25
+ * @param title
26
+ * @param task
27
+ * @returns
28
+ */
29
+ export const trace =
30
+ (title: string) =>
31
+ async <T>(task: Task<T>): Promise<[T, number]> => {
32
+ process.stdout.write(` - ${title}: `);
33
+ const res: [T, number] = await measure(task);
34
+
35
+ console.log(`${res[1].toLocaleString()} ms`);
36
+ return res;
37
+ };
38
+ }
@@ -1,4 +1,4 @@
1
- import { is_sorted } from "tstl/ranges";
1
+ import { ranges } from "tstl";
2
2
 
3
3
  import { RandomGenerator } from "./RandomGenerator";
4
4
  import { json_equal_to } from "./internal/json_equal_to";
@@ -68,7 +68,11 @@ export namespace TestValidator {
68
68
  const diff: string[] = json_equal_to(exception)(x)(y);
69
69
  if (diff.length)
70
70
  throw new Error(
71
- `Bug on ${title}: found different values - [${diff.join(", ")}]`,
71
+ [
72
+ `Bug on ${title}: found different values - [${diff.join(", ")}]:`,
73
+ "\n",
74
+ JSON.stringify({ x, y }, null, 2),
75
+ ].join("\n"),
72
76
  );
73
77
  };
74
78
 
@@ -300,7 +304,7 @@ export namespace TestValidator {
300
304
 
301
305
  const reversed: typeof comp =
302
306
  direction === "+" ? comp : (x, y) => comp(y, x);
303
- if (is_sorted(data, (x, y) => reversed(x, y) < 0) === false) {
307
+ if (ranges.is_sorted(data, (x, y) => reversed(x, y) < 0) === false) {
304
308
  if (
305
309
  fields.length === 1 &&
306
310
  data.length &&
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as e2e from "./module";
2
-
3
- export default e2e;
4
- export * from "./module";
1
+ import * as e2e from "./module";
2
+
3
+ export default e2e;
4
+ export * from "./module";
@@ -1,34 +1,34 @@
1
- export const json_equal_to =
2
- (exception: (key: string) => boolean) =>
3
- <T>(x: T) =>
4
- (y: T): string[] => {
5
- const container: string[] = [];
6
- const iterate =
7
- (accessor: string) =>
8
- (x: any) =>
9
- (y: any): void => {
10
- if (typeof x !== typeof y) container.push(accessor);
11
- else if (x instanceof Array)
12
- if (!(y instanceof Array)) container.push(accessor);
13
- else array(accessor)(x)(y);
14
- else if (x instanceof Object) object(accessor)(x)(y);
15
- else if (x !== y) container.push(accessor);
16
- };
17
- const array =
18
- (accessor: string) =>
19
- (x: any[]) =>
20
- (y: any[]): void => {
21
- if (x.length !== y.length) container.push(`${accessor}.length`);
22
- x.forEach((xItem, i) => iterate(`${accessor}[${i}]`)(xItem)(y[i]));
23
- };
24
- const object =
25
- (accessor: string) =>
26
- (x: any) =>
27
- (y: any): void =>
28
- Object.keys(x)
29
- .filter((key) => x[key] !== undefined && !exception(key))
30
- .forEach((key) => iterate(`${accessor}.${key}`)(x[key])(y[key]));
31
-
32
- iterate("")(x)(y);
33
- return container;
34
- };
1
+ export const json_equal_to =
2
+ (exception: (key: string) => boolean) =>
3
+ <T>(x: T) =>
4
+ (y: T): string[] => {
5
+ const container: string[] = [];
6
+ const iterate =
7
+ (accessor: string) =>
8
+ (x: any) =>
9
+ (y: any): void => {
10
+ if (typeof x !== typeof y) container.push(accessor);
11
+ else if (x instanceof Array)
12
+ if (!(y instanceof Array)) container.push(accessor);
13
+ else array(accessor)(x)(y);
14
+ else if (x instanceof Object) object(accessor)(x)(y);
15
+ else if (x !== y) container.push(accessor);
16
+ };
17
+ const array =
18
+ (accessor: string) =>
19
+ (x: any[]) =>
20
+ (y: any[]): void => {
21
+ if (x.length !== y.length) container.push(`${accessor}.length`);
22
+ x.forEach((xItem, i) => iterate(`${accessor}[${i}]`)(xItem)(y[i]));
23
+ };
24
+ const object =
25
+ (accessor: string) =>
26
+ (x: any) =>
27
+ (y: any): void =>
28
+ Object.keys(x)
29
+ .filter((key) => x[key] !== undefined && !exception(key))
30
+ .forEach((key) => iterate(`${accessor}.${key}`)(x[key])(y[key]));
31
+
32
+ iterate("")(x)(y);
33
+ return container;
34
+ };
package/src/module.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./ArrayUtil";
2
- export * from "./DynamicExecutor";
3
- export * from "./GaffComparator";
4
- export * from "./RandomGenerator";
5
- export * from "./StopWatch";
6
- export * from "./TestValidator";
1
+ export * from "./ArrayUtil";
2
+ export * from "./DynamicExecutor";
3
+ export * from "./GaffComparator";
4
+ export * from "./RandomGenerator";
5
+ export * from "./StopWatch";
6
+ export * from "./TestValidator";