randex 1.1.0 → 1.4.0
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/.vscode/settings.json +1 -1
- package/README.md +20 -0
- package/eslint.config.js +29 -0
- package/lib/basic/set.js +48 -51
- package/lib/basic/type.js +27 -34
- package/lib/custom/bool.js +1 -2
- package/lib/custom/email.js +8 -9
- package/lib/custom/filenameX.js +7 -8
- package/lib/custom/fullnameX.js +7 -8
- package/lib/custom/index.d.ts +10 -8
- package/lib/custom/index.js +64 -45
- package/lib/custom/number.js +11 -12
- package/lib/custom/phrase.js +11 -12
- package/lib/custom/random.js +23 -29
- package/lib/custom/sentence.js +13 -14
- package/lib/custom/singleName.js +7 -8
- package/lib/custom/username.js +6 -7
- package/lib/custom/word.js +9 -10
- package/lib/index.js +1 -2
- package/lib/test/array.test.js +10 -13
- package/lib/test/arrayItem.test.js +17 -0
- package/lib/test/email.test.js +35 -35
- package/lib/test/filename.test.js +38 -38
- package/lib/test/fullname.test.js +7 -7
- package/lib/test/markdown.test.js +14 -14
- package/lib/test/name.test.js +13 -13
- package/lib/test/number.many.test.js +21 -24
- package/lib/test/number.test.js +26 -27
- package/lib/test/params.test.js +51 -51
- package/lib/test/phrase.test.js +22 -22
- package/lib/test/random.test.js +36 -38
- package/lib/test/sentence.test.js +22 -22
- package/lib/test/{set-util.test.js → setUtil.test.js} +7 -7
- package/lib/test/shuffle.test.d.ts +1 -0
- package/lib/test/shuffle.test.js +14 -0
- package/lib/test/spreader.test.js +13 -12
- package/lib/test/testUtil.js +121 -0
- package/lib/test/type.test.js +11 -14
- package/lib/test/username.test.js +11 -11
- package/lib/test/word.test.js +16 -16
- package/lib/utils/spreader.d.ts +1 -0
- package/lib/utils/spreader.js +19 -25
- package/package.json +4 -4
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -3
- package/lib/test/array-item.test.js +0 -18
- package/lib/test/test-util.js +0 -134
- /package/lib/test/{array-item.test.d.ts → arrayItem.test.d.ts} +0 -0
- /package/lib/test/{set-util.test.d.ts → setUtil.test.d.ts} +0 -0
- /package/lib/test/{test-util.d.ts → testUtil.d.ts} +0 -0
package/lib/test/name.test.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
describe("randomName",
|
|
6
|
-
it("simple",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
expect(
|
|
3
|
+
const custom_1 = require("../custom");
|
|
4
|
+
const testUtil_1 = require("./testUtil");
|
|
5
|
+
describe("randomName", () => {
|
|
6
|
+
it("simple", () => {
|
|
7
|
+
testUtil_1.TestUtil.loop(() => {
|
|
8
|
+
const value = custom_1.Randex.singleName();
|
|
9
|
+
expect(testUtil_1.TestUtil.isNameValid(value)).toBeTruthy();
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
|
-
it("options: length",
|
|
13
|
-
|
|
12
|
+
it("options: length", () => {
|
|
13
|
+
let value = custom_1.Randex.singleName({ length: 5 });
|
|
14
14
|
expect(value.length).toBe(5);
|
|
15
15
|
value = custom_1.Randex.singleName(5);
|
|
16
16
|
expect(value.length).toBe(5);
|
|
@@ -21,12 +21,12 @@ describe("randomName", function () {
|
|
|
21
21
|
expect(value.length).toBe(5);
|
|
22
22
|
//
|
|
23
23
|
value = custom_1.Randex.singleName({ length: [1, 5] });
|
|
24
|
-
expect(
|
|
24
|
+
expect(testUtil_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
|
|
25
25
|
value = custom_1.Randex.singleName([1, 5]);
|
|
26
|
-
expect(
|
|
26
|
+
expect(testUtil_1.TestUtil.inNumberRange(value.length, [1, 5])).toBeTruthy();
|
|
27
27
|
});
|
|
28
|
-
it("options: alphabet",
|
|
29
|
-
|
|
28
|
+
it("options: alphabet", () => {
|
|
29
|
+
let value = custom_1.Randex.singleName({ alphabet: "russian", length: 5 });
|
|
30
30
|
expect(value.length).toBe(5);
|
|
31
31
|
value = custom_1.Randex.singleName("french", 10);
|
|
32
32
|
expect(value.length).toBe(10);
|
|
@@ -1,49 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const custom_1 = require("../custom");
|
|
4
4
|
function testNumber(min, max, count) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
for (
|
|
8
|
-
|
|
5
|
+
const value = custom_1.Randex.many(count).number([min, max]);
|
|
6
|
+
const uniqueResult = [];
|
|
7
|
+
for (let i = 0; i < count; i++) {
|
|
8
|
+
const uniqueValue = value[i];
|
|
9
9
|
expect(value[i]).toBeGreaterThanOrEqual(min);
|
|
10
10
|
expect(value[i]).toBeLessThanOrEqual(max);
|
|
11
11
|
uniqueResult.push(uniqueValue);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
describe("random many number",
|
|
15
|
-
it("param: number",
|
|
14
|
+
describe("random many number", () => {
|
|
15
|
+
it("param: number", () => {
|
|
16
16
|
testNumber(0, 2, 0);
|
|
17
17
|
testNumber(1, 5, 1);
|
|
18
18
|
testNumber(5, 10, 2);
|
|
19
19
|
});
|
|
20
|
-
it("param: big number",
|
|
20
|
+
it("param: big number", () => {
|
|
21
21
|
testNumber(50, 500, 50);
|
|
22
22
|
});
|
|
23
|
-
it("max count - unique",
|
|
23
|
+
it("max count - unique", () => {
|
|
24
24
|
testNumber(10, 20, 11);
|
|
25
25
|
});
|
|
26
|
-
it("count limit",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
it("count limit", () => {
|
|
27
|
+
const min = 5;
|
|
28
|
+
const max = 10;
|
|
29
|
+
const count = max - min + 1;
|
|
30
|
+
let value = custom_1.Randex.many(count).number([min, max]);
|
|
31
31
|
expect(value.length).toBe(count);
|
|
32
32
|
// max length limit
|
|
33
33
|
value = custom_1.Randex.many(count + 10).number([min, max]);
|
|
34
34
|
expect(value.length).toBe(count + 10);
|
|
35
35
|
});
|
|
36
|
-
it.skip("range: fill all possible values",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
it.skip("range: fill all possible values", () => {
|
|
37
|
+
const min = 5;
|
|
38
|
+
const max = 10;
|
|
39
|
+
const count = max - min + 1;
|
|
40
|
+
const value = custom_1.Randex.many(count + 10).number([min, max]);
|
|
41
41
|
expect(value.length).toBe(count + 10);
|
|
42
|
-
|
|
43
|
-
expect(value.find(
|
|
44
|
-
};
|
|
45
|
-
for (var i = min; i <= max; i++) {
|
|
46
|
-
_loop_1(i);
|
|
42
|
+
for (let i = min; i <= max; i++) {
|
|
43
|
+
expect(value.find(x => x === i)).toBeTruthy();
|
|
47
44
|
}
|
|
48
45
|
});
|
|
49
46
|
});
|
package/lib/test/number.test.js
CHANGED
|
@@ -1,60 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const custom_1 = require("../custom");
|
|
4
|
+
const testUtil_1 = require("./testUtil");
|
|
5
5
|
function testNumber(max) {
|
|
6
|
-
|
|
6
|
+
const value = custom_1.Randex.number(max);
|
|
7
7
|
expect(value).toBeGreaterThanOrEqual(0);
|
|
8
8
|
expect(value).toBeLessThanOrEqual(max);
|
|
9
9
|
}
|
|
10
|
-
function testNumberWithArray(range, two) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var value = two ? custom_1.Randex.number(range) : custom_1.Randex.number(min, max);
|
|
10
|
+
function testNumberWithArray(range, two = false) {
|
|
11
|
+
const [min, max] = range;
|
|
12
|
+
const value = two ? custom_1.Randex.number(range) : custom_1.Randex.number(min, max);
|
|
14
13
|
expect(value).toBeGreaterThanOrEqual(min);
|
|
15
14
|
expect(value).toBeLessThanOrEqual(max);
|
|
16
15
|
}
|
|
17
|
-
describe("randomNumber",
|
|
18
|
-
it("param: number",
|
|
16
|
+
describe("randomNumber", () => {
|
|
17
|
+
it("param: number", () => {
|
|
19
18
|
testNumber(0);
|
|
20
19
|
testNumber(1);
|
|
21
20
|
testNumber(5);
|
|
22
21
|
});
|
|
23
|
-
it("much range",
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
it("much range", () => {
|
|
23
|
+
const max = 4;
|
|
24
|
+
const result = {};
|
|
25
|
+
testUtil_1.TestUtil.loop(() => {
|
|
26
|
+
const value = custom_1.Randex.number(max);
|
|
28
27
|
result[value] = (result[value] || 0) + 1;
|
|
29
28
|
});
|
|
30
|
-
for (
|
|
29
|
+
for (let i = 0; i <= max; i++) {
|
|
31
30
|
expect(result[i]).toBeGreaterThan(0);
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
|
-
it("param: number array",
|
|
35
|
-
|
|
33
|
+
it("param: number array", () => {
|
|
34
|
+
testUtil_1.TestUtil.loop(() => {
|
|
36
35
|
testNumberWithArray([10, 15]);
|
|
37
36
|
});
|
|
38
37
|
});
|
|
39
|
-
it("param: two numbers",
|
|
40
|
-
|
|
38
|
+
it("param: two numbers", () => {
|
|
39
|
+
testUtil_1.TestUtil.loop(() => {
|
|
41
40
|
testNumberWithArray([10, 15], true);
|
|
42
41
|
});
|
|
43
42
|
});
|
|
44
|
-
it("two numbers with decimals",
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
it("two numbers with decimals", () => {
|
|
44
|
+
let count = 0;
|
|
45
|
+
testUtil_1.TestUtil.loop(() => {
|
|
46
|
+
const value = custom_1.Randex.number(1, 10, { decimals: 2 });
|
|
48
47
|
if (/\.\d{2}$/g.test(value.toString())) {
|
|
49
48
|
count++;
|
|
50
49
|
}
|
|
51
50
|
});
|
|
52
51
|
expect(count).toBeGreaterThan(1);
|
|
53
52
|
});
|
|
54
|
-
it("a number with decimals",
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
it("a number with decimals", () => {
|
|
54
|
+
let count = 0;
|
|
55
|
+
testUtil_1.TestUtil.loop(() => {
|
|
56
|
+
const value = custom_1.Randex.number(10, { decimals: 2 });
|
|
58
57
|
if (/\.\d{2}$/g.test(value.toString())) {
|
|
59
58
|
count++;
|
|
60
59
|
}
|
package/lib/test/params.test.js
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
describe("random params",
|
|
6
|
-
it("array 1",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const testUtil_1 = require("./testUtil");
|
|
4
|
+
const custom_1 = require("../custom");
|
|
5
|
+
describe("random params", () => {
|
|
6
|
+
it("array 1", () => {
|
|
7
|
+
const set = "english";
|
|
8
|
+
const result1 = custom_1.Randex.random({ set });
|
|
9
|
+
const result2 = custom_1.Randex.random(set);
|
|
10
|
+
testUtil_1.TestUtil.testInSet(result1, set);
|
|
11
|
+
testUtil_1.TestUtil.testInSet(result2, set);
|
|
12
12
|
});
|
|
13
|
-
it("single: array",
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
it("single: array", () => {
|
|
14
|
+
const set = ["number", "english"];
|
|
15
|
+
const result1 = custom_1.Randex.random({ set });
|
|
16
|
+
const result2 = custom_1.Randex.random(set);
|
|
17
|
+
testUtil_1.TestUtil.testInSet(result1, set);
|
|
18
|
+
testUtil_1.TestUtil.testInSet(result2, set);
|
|
19
19
|
});
|
|
20
|
-
it("single: array, length",
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
it("single: array, length", () => {
|
|
21
|
+
const set = ["number", "english"];
|
|
22
|
+
const length = 3;
|
|
23
|
+
const result1 = custom_1.Randex.random({ set, length });
|
|
24
|
+
const result2 = custom_1.Randex.random([set, length]);
|
|
25
|
+
testUtil_1.TestUtil.testInSet(result1, set, length);
|
|
26
|
+
testUtil_1.TestUtil.testInSet(result2, set, length);
|
|
27
27
|
});
|
|
28
|
-
it("single: array, length as array",
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
it("single: array, length as array", () => {
|
|
29
|
+
const set = ["number", "english"];
|
|
30
|
+
const length = [1, 4];
|
|
31
|
+
const result1 = custom_1.Randex.random({ set, length });
|
|
32
|
+
const result2 = custom_1.Randex.random([set, length]);
|
|
33
|
+
testUtil_1.TestUtil.testInSet(result1, set, length);
|
|
34
|
+
testUtil_1.TestUtil.testInSet(result2, set, length);
|
|
35
35
|
});
|
|
36
|
-
it("array 2 (range)",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
it("array 2 (range)", () => {
|
|
37
|
+
const set = "number";
|
|
38
|
+
const range = "abcdefghijklmnopqrstuvwxyz";
|
|
39
|
+
const result1 = custom_1.Randex.random({ set, charRange: range });
|
|
40
|
+
const result2 = custom_1.Randex.random([set, range]);
|
|
41
|
+
testUtil_1.TestUtil.testInBoth(result1, set, range);
|
|
42
|
+
testUtil_1.TestUtil.testInBoth(result2, set, range);
|
|
43
43
|
});
|
|
44
|
-
it("array 2 (length)",
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
it("array 2 (length)", () => {
|
|
45
|
+
const set = "english";
|
|
46
|
+
const length = 3;
|
|
47
|
+
const result1 = custom_1.Randex.random({ set, length });
|
|
48
|
+
const result2 = custom_1.Randex.random([set, length]);
|
|
49
|
+
testUtil_1.TestUtil.testInSet(result1, set, length);
|
|
50
|
+
testUtil_1.TestUtil.testInSet(result2, set, length);
|
|
51
51
|
});
|
|
52
|
-
it("array 3",
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
it("array 3", () => {
|
|
53
|
+
const set = "number";
|
|
54
|
+
const range = "abcdefghijklmnopqrstuvwxyz";
|
|
55
|
+
const length = 3;
|
|
56
|
+
const result1 = custom_1.Randex.random({ set, charRange: range, length });
|
|
57
|
+
const result2 = custom_1.Randex.random([set, range, length]);
|
|
58
|
+
testUtil_1.TestUtil.testInBoth(result1, set, range, length);
|
|
59
|
+
testUtil_1.TestUtil.testInBoth(result2, set, range, length);
|
|
60
60
|
});
|
|
61
61
|
});
|
package/lib/test/phrase.test.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
describe("phrase",
|
|
6
|
-
it("default",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
expect(
|
|
3
|
+
const custom_1 = require("../custom");
|
|
4
|
+
const testUtil_1 = require("./testUtil");
|
|
5
|
+
describe("phrase", () => {
|
|
6
|
+
it("default", () => {
|
|
7
|
+
testUtil_1.TestUtil.loop(() => {
|
|
8
|
+
const text = custom_1.Randex.phrase();
|
|
9
|
+
expect(testUtil_1.TestUtil.isPhraseValid(text)).toBeTruthy();
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
|
-
it("range",
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
expect(
|
|
12
|
+
it("range", () => {
|
|
13
|
+
const range = [10, 20];
|
|
14
|
+
testUtil_1.TestUtil.loop(() => {
|
|
15
|
+
const text = custom_1.Randex.phrase(range);
|
|
16
|
+
expect(testUtil_1.TestUtil.isPhraseValid(text, range)).toBeTruthy();
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
|
-
it("specific number",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
expect(
|
|
19
|
+
it("specific number", () => {
|
|
20
|
+
const range = 5;
|
|
21
|
+
testUtil_1.TestUtil.loop(() => {
|
|
22
|
+
const text = custom_1.Randex.phrase(range);
|
|
23
|
+
expect(testUtil_1.TestUtil.isPhraseValid(text, range)).toBeTruthy();
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
|
-
it("many",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (
|
|
30
|
-
expect(
|
|
26
|
+
it("many", () => {
|
|
27
|
+
const count = 5;
|
|
28
|
+
const phrases = custom_1.Randex.many(count).phrase();
|
|
29
|
+
for (let i = 0; i < count; i++) {
|
|
30
|
+
expect(testUtil_1.TestUtil.isPhraseValid(phrases[i])).toBeTruthy();
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
});
|
package/lib/test/random.test.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function inSet(set, length) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
test_util_1.TestUtil.testInSet(result, set, length);
|
|
3
|
+
const testUtil_1 = require("./testUtil");
|
|
4
|
+
const custom_1 = require("../custom");
|
|
5
|
+
function inSet(set, length = 1) {
|
|
6
|
+
const result = custom_1.Randex.random({ set, length });
|
|
7
|
+
testUtil_1.TestUtil.testInSet(result, set, length);
|
|
9
8
|
}
|
|
10
|
-
function inRange(range, length) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
test_util_1.TestUtil.testInRange(result, range, length);
|
|
9
|
+
function inRange(range, length = 1) {
|
|
10
|
+
const result = custom_1.Randex.random({ charRange: range, length });
|
|
11
|
+
testUtil_1.TestUtil.testInRange(result, range, length);
|
|
14
12
|
}
|
|
15
|
-
describe("random",
|
|
16
|
-
it("set",
|
|
13
|
+
describe("random", () => {
|
|
14
|
+
it("set", () => {
|
|
17
15
|
inSet("english", 3);
|
|
18
16
|
inSet(["english", "l"], 3);
|
|
19
17
|
inSet(["english", "u"], 3);
|
|
@@ -22,64 +20,64 @@ describe("random", function () {
|
|
|
22
20
|
inSet("number", 3);
|
|
23
21
|
inSet("binary", 3);
|
|
24
22
|
});
|
|
25
|
-
it("range",
|
|
23
|
+
it("range", () => {
|
|
26
24
|
inRange("abc", 3);
|
|
27
25
|
inRange("1234abc!@#", 3);
|
|
28
26
|
});
|
|
29
|
-
it("result 1: number",
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
it("result 1: number", () => {
|
|
28
|
+
const length = [0, 4];
|
|
29
|
+
const result = {};
|
|
30
|
+
testUtil_1.TestUtil.loop(() => {
|
|
31
|
+
const l = custom_1.Randex.random({ set: "english", length }).length;
|
|
34
32
|
result[l] = (result[l] || 0) + 1;
|
|
35
33
|
});
|
|
36
|
-
for (
|
|
34
|
+
for (let i = 0; i <= 4; i++) {
|
|
37
35
|
expect(result[i]).toBeGreaterThan(0);
|
|
38
36
|
}
|
|
39
37
|
});
|
|
40
|
-
it("result 2: number range",
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
it("result 2: number range", () => {
|
|
39
|
+
const length = [5, 8];
|
|
40
|
+
const result = {};
|
|
41
|
+
testUtil_1.TestUtil.loop(() => {
|
|
42
|
+
const l = custom_1.Randex.random({ set: "english", length }).length;
|
|
45
43
|
result[l] = (result[l] || 0) + 1;
|
|
46
44
|
});
|
|
47
|
-
for (
|
|
45
|
+
for (let i = 5; i <= 8; i++) {
|
|
48
46
|
expect(result[i]).toBeGreaterThan(0);
|
|
49
47
|
}
|
|
50
48
|
});
|
|
51
|
-
it("length: alphabet",
|
|
49
|
+
it("length: alphabet", () => {
|
|
52
50
|
inSet("english", 0);
|
|
53
51
|
inSet("english", [0, 0]);
|
|
54
52
|
inSet("english", [1, 3]);
|
|
55
53
|
inSet("english", [0, 1]);
|
|
56
54
|
});
|
|
57
|
-
it("length: alphabet",
|
|
58
|
-
|
|
55
|
+
it("length: alphabet", () => {
|
|
56
|
+
let value = custom_1.Randex.random("english");
|
|
59
57
|
expect(value.length).toBe(1);
|
|
60
58
|
value = custom_1.Randex.random(["english", "l"]);
|
|
61
59
|
expect(value.length).toBe(1);
|
|
62
60
|
});
|
|
63
|
-
it("alphabet: upper",
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
expect(
|
|
61
|
+
it("alphabet: upper", () => {
|
|
62
|
+
testUtil_1.TestUtil.loop(() => {
|
|
63
|
+
let value = custom_1.Randex.random(["english", "u"]);
|
|
64
|
+
expect(testUtil_1.TestUtil.isUpperCharValid(value, 1)).toBeTruthy();
|
|
67
65
|
value = custom_1.Randex.random([
|
|
68
66
|
["english", "u"],
|
|
69
67
|
[1, 3],
|
|
70
68
|
]);
|
|
71
|
-
expect(
|
|
69
|
+
expect(testUtil_1.TestUtil.isUpperCharValid(value, [1, 3])).toBeTruthy();
|
|
72
70
|
});
|
|
73
71
|
});
|
|
74
|
-
it("alphabet: lower",
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
expect(
|
|
72
|
+
it("alphabet: lower", () => {
|
|
73
|
+
testUtil_1.TestUtil.loop(() => {
|
|
74
|
+
let value = custom_1.Randex.random(["english", "l"]);
|
|
75
|
+
expect(testUtil_1.TestUtil.isLowerCharValid(value, 1)).toBeTruthy();
|
|
78
76
|
value = custom_1.Randex.random([
|
|
79
77
|
["english", "lower"],
|
|
80
78
|
[1, 3],
|
|
81
79
|
]);
|
|
82
|
-
expect(
|
|
80
|
+
expect(testUtil_1.TestUtil.isLowerCharValid(value, [1, 3])).toBeTruthy();
|
|
83
81
|
});
|
|
84
82
|
});
|
|
85
83
|
});
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
describe("sentence",
|
|
6
|
-
it("default",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
expect(
|
|
3
|
+
const custom_1 = require("../custom");
|
|
4
|
+
const testUtil_1 = require("./testUtil");
|
|
5
|
+
describe("sentence", () => {
|
|
6
|
+
it("default", () => {
|
|
7
|
+
testUtil_1.TestUtil.loop(() => {
|
|
8
|
+
const text = custom_1.Randex.sentence();
|
|
9
|
+
expect(testUtil_1.TestUtil.isSentenceValid(text)).toBeTruthy();
|
|
10
10
|
});
|
|
11
11
|
});
|
|
12
|
-
it("range",
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
expect(
|
|
12
|
+
it("range", () => {
|
|
13
|
+
const range = [10, 20];
|
|
14
|
+
testUtil_1.TestUtil.loop(() => {
|
|
15
|
+
const text = custom_1.Randex.sentence(range);
|
|
16
|
+
expect(testUtil_1.TestUtil.isSentenceValid(text, range)).toBeTruthy();
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
|
-
it("specific number",
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
expect(
|
|
19
|
+
it("specific number", () => {
|
|
20
|
+
const range = 5;
|
|
21
|
+
testUtil_1.TestUtil.loop(() => {
|
|
22
|
+
const text = custom_1.Randex.sentence(range);
|
|
23
|
+
expect(testUtil_1.TestUtil.isSentenceValid(text, range)).toBeTruthy();
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
|
-
it("many",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (
|
|
30
|
-
expect(
|
|
26
|
+
it("many", () => {
|
|
27
|
+
const count = 5;
|
|
28
|
+
const sentences = custom_1.Randex.many(count).sentence();
|
|
29
|
+
for (let i = 0; i < count; i++) {
|
|
30
|
+
expect(testUtil_1.TestUtil.isSentenceValid(sentences[i])).toBeTruthy();
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const set_1 = require("../basic/set");
|
|
4
|
+
const defaultLength = [1, 10];
|
|
5
5
|
function getLength(reservedChars, length, resultLength) {
|
|
6
|
-
|
|
6
|
+
const result = set_1.RandexSetUtil.getLength(reservedChars, length, defaultLength);
|
|
7
7
|
if (typeof resultLength === "number") {
|
|
8
8
|
expect(result).toBe(resultLength);
|
|
9
9
|
}
|
|
@@ -11,15 +11,15 @@ function getLength(reservedChars, length, resultLength) {
|
|
|
11
11
|
expect(result).toMatchObject(resultLength);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
describe("RandexSetUtil",
|
|
15
|
-
describe("getLength",
|
|
16
|
-
it("single",
|
|
14
|
+
describe("RandexSetUtil", () => {
|
|
15
|
+
describe("getLength", () => {
|
|
16
|
+
it("single", () => {
|
|
17
17
|
getLength(0, 2, 2);
|
|
18
18
|
getLength(1, 3, 2);
|
|
19
19
|
getLength(0, undefined, defaultLength);
|
|
20
20
|
getLength(5, 3, defaultLength);
|
|
21
21
|
});
|
|
22
|
-
it("array",
|
|
22
|
+
it("array", () => {
|
|
23
23
|
getLength(0, [1, 2], [1, 2]);
|
|
24
24
|
getLength(1, [2, 3], [1, 2]);
|
|
25
25
|
getLength(3, [1, 5], defaultLength);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const custom_1 = require("../custom");
|
|
4
|
+
describe("shuffle", () => {
|
|
5
|
+
it("shuffles the array in place and returns it", () => {
|
|
6
|
+
const array = [1, 2, 3];
|
|
7
|
+
const randomSpy = jest.spyOn(Math, "random");
|
|
8
|
+
randomSpy.mockReturnValueOnce(0).mockReturnValueOnce(0.5).mockReturnValueOnce(0.99);
|
|
9
|
+
const result = custom_1.Randex.shuffle(array);
|
|
10
|
+
expect(result).toBe(array);
|
|
11
|
+
expect(array).toEqual([3, 2, 1]);
|
|
12
|
+
randomSpy.mockRestore();
|
|
13
|
+
});
|
|
14
|
+
});
|