UNPKG

9.45 kBJavaScriptView Raw
1"use strict";
2/**
3 * This file is part of the @egodigital/egoose distribution.
4 * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
5 *
6 * @egodigital/egoose is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * @egodigital/egoose is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19const assert = require("assert");
20const mocha_1 = require("mocha");
21const index_1 = require("../index");
22mocha_1.describe('#asArray()', function () {
23 mocha_1.describe('(null)', function () {
24 mocha_1.it('should return empty array when all values are (null)', function () {
25 for (let i = 0; i < 1000; i++) {
26 const ARR = new Array(i);
27 ARR.fill(null);
28 const NEW_ARR = index_1.asArray(ARR);
29 assert.ok(Array.isArray(NEW_ARR));
30 assert.equal(NEW_ARR.length, 0);
31 assert.strictEqual(NEW_ARR.length, 0);
32 NEW_ARR.forEach(x => {
33 assert.equal(x, null);
34 assert.strictEqual(x, null);
35 });
36 }
37 });
38 mocha_1.it('should return array of same length when all values are (null)', function () {
39 for (let i = 0; i < 1000; i++) {
40 const ARR = new Array(i);
41 ARR.fill(null);
42 const NEW_ARR = index_1.asArray(ARR, false);
43 assert.ok(Array.isArray(NEW_ARR));
44 assert.equal(NEW_ARR.length, ARR.length);
45 assert.strictEqual(NEW_ARR.length, ARR.length);
46 assert.notStrictEqual(NEW_ARR, ARR);
47 NEW_ARR.forEach(x => {
48 assert.equal(x, null);
49 assert.strictEqual(x, null);
50 });
51 }
52 });
53 mocha_1.it('should return an empty array', function () {
54 const VAL = null;
55 const ARR = index_1.asArray(VAL);
56 assert.ok(Array.isArray(ARR));
57 assert.equal(ARR.length, 0);
58 assert.strictEqual(ARR.length, 0);
59 });
60 mocha_1.it('should return an array with a single element', function () {
61 const VAL = null;
62 const EXPECTED = [VAL];
63 const ACTUAL = index_1.asArray(VAL, false);
64 assert.ok(Array.isArray(ACTUAL));
65 assert.equal(ACTUAL.length, 1);
66 assert.strictEqual(ACTUAL.length, 1);
67 assert.ok(null === ACTUAL[0]);
68 assert.equal(ACTUAL[0], EXPECTED[0]);
69 assert.strictEqual(ACTUAL[0], EXPECTED[0]);
70 });
71 });
72 mocha_1.describe('(undefined)', function () {
73 mocha_1.it('should return empty array when all values are (undefined)', function () {
74 for (let i = 0; i < 1000; i++) {
75 const ARR = new Array(i);
76 ARR.fill(undefined);
77 const NEW_ARR = index_1.asArray(ARR);
78 assert.ok(Array.isArray(NEW_ARR));
79 assert.equal(NEW_ARR.length, 0);
80 assert.strictEqual(NEW_ARR.length, 0);
81 NEW_ARR.forEach(x => {
82 assert.equal(x, undefined);
83 assert.strictEqual(x, undefined);
84 });
85 }
86 });
87 mocha_1.it('should return array of same length when all values are (undefined)', function () {
88 for (let i = 0; i < 1000; i++) {
89 const ARR = new Array(i);
90 ARR.fill(undefined);
91 const NEW_ARR = index_1.asArray(ARR, false);
92 assert.ok(Array.isArray(NEW_ARR));
93 assert.equal(NEW_ARR.length, ARR.length);
94 assert.strictEqual(NEW_ARR.length, ARR.length);
95 assert.notStrictEqual(NEW_ARR, ARR);
96 NEW_ARR.forEach(x => {
97 assert.equal(x, undefined);
98 assert.strictEqual(x, undefined);
99 });
100 }
101 });
102 mocha_1.it('should return an empty array', function () {
103 const VAL = undefined;
104 const ARR = index_1.asArray(VAL);
105 assert.ok(Array.isArray(ARR));
106 assert.equal(ARR.length, 0);
107 assert.strictEqual(ARR.length, 0);
108 });
109 mocha_1.it('should return an array with a single element', function () {
110 const VAL = undefined;
111 const EXPECTED = [VAL];
112 const ACTUAL = index_1.asArray(VAL, false);
113 assert.ok(Array.isArray(ACTUAL));
114 assert.equal(ACTUAL.length, 1);
115 assert.strictEqual(ACTUAL.length, 1);
116 assert.ok('undefined' === typeof ACTUAL[0]);
117 assert.equal(ACTUAL[0], EXPECTED[0]);
118 assert.strictEqual(ACTUAL[0], EXPECTED[0]);
119 });
120 });
121 mocha_1.describe('String', function () {
122 mocha_1.it('should return array with same values a input', function () {
123 for (let i = 0; i < 1000; i++) {
124 const ARR = new Array(i);
125 ARR.fill('' + i);
126 const NEW_ARR = index_1.asArray(ARR);
127 assert.ok(Array.isArray(NEW_ARR));
128 assert.equal(NEW_ARR.length, ARR.length);
129 assert.strictEqual(NEW_ARR.length, ARR.length);
130 assert.notStrictEqual(NEW_ARR, ARR);
131 for (let j = 0; j < NEW_ARR.length; j++) {
132 assert.equal(NEW_ARR[j], ARR[j]);
133 assert.strictEqual(NEW_ARR[j], ARR[j]);
134 }
135 }
136 });
137 mocha_1.it('should return array with same values a input', function () {
138 for (let i = 0; i < 1000; i++) {
139 const ARR = new Array(i);
140 ARR.fill('' + i);
141 const NEW_ARR = index_1.asArray(ARR, false);
142 assert.ok(Array.isArray(NEW_ARR));
143 assert.equal(NEW_ARR.length, ARR.length);
144 assert.strictEqual(NEW_ARR.length, ARR.length);
145 assert.notStrictEqual(NEW_ARR, ARR);
146 for (let j = 0; j < NEW_ARR.length; j++) {
147 assert.equal(NEW_ARR[j], ARR[j]);
148 assert.strictEqual(NEW_ARR[j], ARR[j]);
149 }
150 }
151 });
152 mocha_1.it('should return array with a single item', function () {
153 for (let i = 1; i <= 1000; i++) {
154 const STR = 'TM'.repeat(i);
155 const EXPECTED = [STR];
156 const ACTUAL = index_1.asArray(STR);
157 assert.ok(Array.isArray(ACTUAL));
158 assert.equal(ACTUAL.length, 1);
159 assert.strictEqual(ACTUAL.length, 1);
160 assert.ok('string' === typeof ACTUAL[0]);
161 assert.equal(ACTUAL[0], EXPECTED[0]);
162 assert.strictEqual(ACTUAL[0], EXPECTED[0]);
163 }
164 });
165 });
166 mocha_1.describe('Number', function () {
167 mocha_1.it('should return array with same values a input', function () {
168 for (let i = 0; i < 1000; i++) {
169 const ARR = new Array(i);
170 ARR.fill(i);
171 const NEW_ARR = index_1.asArray(ARR);
172 assert.ok(Array.isArray(NEW_ARR));
173 assert.equal(NEW_ARR.length, ARR.length);
174 assert.strictEqual(NEW_ARR.length, ARR.length);
175 assert.notStrictEqual(NEW_ARR, ARR);
176 for (let j = 0; j < NEW_ARR.length; j++) {
177 assert.equal(NEW_ARR[j], ARR[j]);
178 assert.strictEqual(NEW_ARR[j], ARR[j]);
179 }
180 }
181 });
182 mocha_1.it('should return array with same values a input', function () {
183 for (let i = 0; i < 1000; i++) {
184 const ARR = new Array(i);
185 ARR.fill(i);
186 const NEW_ARR = index_1.asArray(ARR, false);
187 assert.ok(Array.isArray(NEW_ARR));
188 assert.equal(NEW_ARR.length, ARR.length);
189 assert.strictEqual(NEW_ARR.length, ARR.length);
190 assert.notStrictEqual(NEW_ARR, ARR);
191 for (let j = 0; j < NEW_ARR.length; j++) {
192 assert.equal(NEW_ARR[j], ARR[j]);
193 assert.strictEqual(NEW_ARR[j], ARR[j]);
194 }
195 }
196 });
197 mocha_1.it('should return array with a single item', function () {
198 for (let i = 1; i <= 1000; i++) {
199 const VAL = i * 5979;
200 const EXPECTED = [VAL];
201 const ACTUAL = index_1.asArray(VAL);
202 assert.ok(Array.isArray(ACTUAL));
203 assert.equal(ACTUAL.length, 1);
204 assert.strictEqual(ACTUAL.length, 1);
205 assert.ok('number' === typeof ACTUAL[0]);
206 assert.equal(ACTUAL[0], EXPECTED[0]);
207 assert.strictEqual(ACTUAL[0], EXPECTED[0]);
208 }
209 });
210 });
211});
212//# sourceMappingURL=asArray.js.map
\No newline at end of file