@rogolev/value 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +319 -1
- package/docs/classes/Expect/toBe.md +61 -0
- package/docs/classes/Expect/toBeArray.md +52 -0
- package/docs/classes/Expect/toBeAssoc.md +53 -0
- package/docs/classes/Expect/toBeBigInt.md +52 -0
- package/docs/classes/Expect/toBeBool.md +53 -0
- package/docs/classes/Expect/toBeBoolean.md +53 -0
- package/docs/classes/Expect/toBeChar.md +53 -0
- package/docs/classes/Expect/toBeClass.md +53 -0
- package/docs/classes/Expect/toBeFloat.md +53 -0
- package/docs/classes/Expect/toBeFunction.md +52 -0
- package/docs/classes/Expect/toBeInfinity.md +53 -0
- package/docs/classes/Expect/toBeInt.md +53 -0
- package/docs/classes/Expect/toBeInteger.md +53 -0
- package/docs/classes/Expect/toBeList.md +53 -0
- package/docs/classes/Expect/toBeNaN.md +53 -0
- package/docs/classes/Expect/toBeNull.md +51 -0
- package/docs/classes/Expect/toBeNumber.md +52 -0
- package/docs/classes/Expect/toBeNumeric.md +53 -0
- package/docs/classes/Expect/toBeObject.md +52 -0
- package/docs/classes/Expect/toBeScalar.md +53 -0
- package/docs/classes/Expect/toBeString.md +52 -0
- package/docs/classes/Expect/toBeSymbol.md +53 -0
- package/docs/classes/Expect/toBeUndefined.md +54 -0
- package/docs/classes/Expect/toEqual.md +69 -0
- package/docs/classes/Expect/toStrictEqual.md +70 -0
- package/docs/classes/Expect.md +87 -0
- package/docs/classes/Type/expectArray.md +63 -0
- package/docs/classes/Type/expectAssoc.md +65 -0
- package/docs/classes/Type/expectBigInt.md +63 -0
- package/docs/classes/Type/expectBool.md +65 -0
- package/docs/classes/Type/expectBoolean.md +65 -0
- package/docs/classes/Type/expectChar.md +63 -0
- package/docs/classes/Type/expectClass.md +63 -0
- package/docs/classes/Type/expectFloat.md +68 -0
- package/docs/classes/Type/expectFunction.md +63 -0
- package/docs/classes/Type/expectInfinity.md +65 -0
- package/docs/classes/Type/expectInt.md +64 -0
- package/docs/classes/Type/expectInteger.md +64 -0
- package/docs/classes/Type/expectList.md +63 -0
- package/docs/classes/Type/expectNaN.md +63 -0
- package/docs/classes/Type/expectNull.md +63 -0
- package/docs/classes/Type/expectNumber.md +63 -0
- package/docs/classes/Type/expectNumeric.md +63 -0
- package/docs/classes/Type/expectObject.md +64 -0
- package/docs/classes/Type/expectScalar.md +63 -0
- package/docs/classes/Type/expectString.md +63 -0
- package/docs/classes/Type/expectSymbol.md +63 -0
- package/docs/classes/Type/expectUndefined.md +63 -0
- package/docs/classes/Type.md +101 -2
- package/docs/classes.md +2 -1
- package/docs/helpers/array/array_chunk.md +80 -0
- package/docs/helpers/array/array_chunk_with_keys.md +81 -0
- package/docs/helpers/array/array_column.md +110 -0
- package/docs/helpers/array/array_combine.md +77 -0
- package/docs/helpers/array/array_count_values.md +71 -0
- package/docs/helpers/array/array_diff.md +97 -0
- package/docs/helpers/array/array_diff_assoc.md +81 -0
- package/docs/helpers/array/array_diff_key.md +81 -0
- package/docs/helpers/array/array_diff_uassoc.md +101 -0
- package/docs/helpers/array/array_diff_ukey.md +101 -0
- package/docs/helpers/array/array_fill.md +81 -0
- package/docs/helpers/array/array_fill_keys.md +73 -0
- package/docs/helpers/array/array_filter.md +79 -0
- package/docs/helpers/array/array_flip.md +70 -0
- package/docs/helpers/array/array_index_max.md +78 -0
- package/docs/helpers/array/array_index_min.md +78 -0
- package/docs/helpers/array/array_intersect.md +91 -0
- package/docs/helpers/array/array_intersect_assoc.md +91 -0
- package/docs/helpers/array/array_intersect_key.md +91 -0
- package/docs/helpers/array/array_intersect_uassoc.md +101 -0
- package/docs/helpers/array/array_intersect_ukey.md +101 -0
- package/docs/helpers/array/array_key_exists.md +73 -0
- package/docs/helpers/array/array_key_first.md +62 -0
- package/docs/helpers/array/array_key_last.md +62 -0
- package/docs/helpers/array/array_key_to_lower_case.md +57 -0
- package/docs/helpers/array/array_key_to_upper_case.md +57 -0
- package/docs/helpers/array/array_keys.md +62 -0
- package/docs/helpers/array/array_map.md +69 -0
- package/docs/helpers/array/array_merge.md +67 -0
- package/docs/helpers/array/array_merge_recursive.md +86 -0
- package/docs/helpers/array/array_pad.md +83 -0
- package/docs/helpers/array/array_pop.md +64 -0
- package/docs/helpers/array/array_product.md +62 -0
- package/docs/helpers/array/array_push.md +57 -0
- package/docs/helpers/array/array_rand.md +99 -0
- package/docs/helpers/array/array_reduce.md +77 -0
- package/docs/helpers/array/array_replace.md +85 -0
- package/docs/helpers/array/array_replace_recursive.md +87 -0
- package/docs/helpers/array/array_reverse.md +55 -0
- package/docs/helpers/array/array_search.md +74 -0
- package/docs/helpers/array/array_shift.md +64 -0
- package/docs/helpers/array/array_slice.md +65 -0
- package/docs/helpers/array/array_splice.md +103 -0
- package/docs/helpers/array/array_sum.md +55 -0
- package/docs/helpers/array/array_udiff.md +97 -0
- package/docs/helpers/array/array_udiff_assoc.md +101 -0
- package/docs/helpers/array/array_udiff_uassoc.md +88 -0
- package/docs/helpers/array/array_uintersect.md +101 -0
- package/docs/helpers/array/array_uintersect_assoc.md +102 -0
- package/docs/helpers/array/array_uintersect_uassoc.md +135 -0
- package/docs/helpers/array/array_unique.md +54 -0
- package/docs/helpers/array/array_unshift.md +58 -0
- package/docs/helpers/array/array_values.md +54 -0
- package/docs/helpers/array/array_walk.md +87 -0
- package/docs/helpers/array/array_walk_recursive.md +93 -0
- package/docs/helpers/array/count.md +54 -0
- package/docs/helpers/array/in_array.md +65 -0
- package/docs/helpers/array/natsort.md +60 -0
- package/docs/helpers/array/range.md +76 -0
- package/docs/helpers/array/shuffle.md +74 -0
- package/docs/helpers/array/sort.md +79 -0
- package/docs/helpers/expect.md +58 -0
- package/docs/helpers/expect_array.md +63 -0
- package/docs/helpers/expect_assoc.md +65 -0
- package/docs/helpers/expect_bigint.md +63 -0
- package/docs/helpers/expect_bool.md +65 -0
- package/docs/helpers/expect_boolean.md +65 -0
- package/docs/helpers/expect_char.md +63 -0
- package/docs/helpers/expect_class.md +63 -0
- package/docs/helpers/expect_float.md +65 -0
- package/docs/helpers/expect_function.md +63 -0
- package/docs/helpers/expect_infinity.md +65 -0
- package/docs/helpers/expect_int.md +65 -0
- package/docs/helpers/expect_integer.md +65 -0
- package/docs/helpers/expect_list.md +63 -0
- package/docs/helpers/expect_nan.md +63 -0
- package/docs/helpers/expect_null.md +63 -0
- package/docs/helpers/expect_number.md +63 -0
- package/docs/helpers/expect_numeric.md +63 -0
- package/docs/helpers/expect_object.md +64 -0
- package/docs/helpers/expect_scalar.md +63 -0
- package/docs/helpers/expect_string.md +63 -0
- package/docs/helpers/expect_symbol.md +63 -0
- package/docs/helpers/expect_undefined.md +64 -0
- package/docs/helpers/is_char.md +84 -0
- package/docs/helpers/is_equal.md +75 -0
- package/docs/helpers/string/is_digit_char.md +70 -0
- package/docs/helpers/string/is_whitespace_char.md +70 -0
- package/docs/helpers/string/natcompare.md +69 -0
- package/docs/helpers/string/natcompare_numeric.md +70 -0
- package/docs/helpers.md +172 -1
- package/index.mjs +91 -1
- package/package.json +1 -1
- package/prettier.config.mjs +2 -1
- package/src/classes/Expect.mjs +1445 -0
- package/src/classes/Type.mjs +2739 -1284
- package/src/constants.mjs +83 -14
- package/src/helpers/array/array_chunk.mjs +102 -0
- package/src/helpers/array/array_chunk_with_keys.mjs +102 -0
- package/src/helpers/array/array_column.mjs +131 -0
- package/src/helpers/array/array_combine.mjs +26 -0
- package/src/helpers/array/array_count_values.mjs +82 -0
- package/src/helpers/array/array_diff.mjs +77 -0
- package/src/helpers/array/array_diff_assoc.mjs +56 -0
- package/src/helpers/array/array_diff_key.mjs +56 -0
- package/src/helpers/array/array_diff_uassoc.mjs +76 -0
- package/src/helpers/array/array_diff_ukey.mjs +71 -0
- package/src/helpers/array/array_fill.mjs +108 -0
- package/src/helpers/array/array_fill_keys.mjs +90 -0
- package/src/helpers/array/array_filter.mjs +105 -0
- package/src/helpers/array/array_flip.mjs +58 -0
- package/src/helpers/array/array_index_max.mjs +82 -0
- package/src/helpers/array/array_index_min.mjs +82 -0
- package/src/helpers/array/array_intersect.mjs +71 -0
- package/src/helpers/array/array_intersect_assoc.mjs +67 -0
- package/src/helpers/array/array_intersect_key.mjs +67 -0
- package/src/helpers/array/array_intersect_uassoc.mjs +77 -0
- package/src/helpers/array/array_intersect_ukey.mjs +72 -0
- package/src/helpers/array/array_key_exists.mjs +83 -0
- package/src/helpers/array/array_key_first.mjs +73 -0
- package/src/helpers/array/array_key_last.mjs +74 -0
- package/src/helpers/array/array_key_to_lower_case.mjs +71 -0
- package/src/helpers/array/array_key_to_upper_case.mjs +71 -0
- package/src/helpers/array/array_keys.mjs +65 -0
- package/src/helpers/array/array_map.mjs +84 -0
- package/src/helpers/array/array_merge.mjs +95 -0
- package/src/helpers/array/array_merge_recursive.mjs +153 -0
- package/src/helpers/array/array_pad.mjs +105 -0
- package/src/helpers/array/array_pop.mjs +82 -0
- package/src/helpers/array/array_product.mjs +67 -0
- package/src/helpers/array/array_push.mjs +75 -0
- package/src/helpers/array/array_rand.mjs +129 -0
- package/src/helpers/array/array_reduce.mjs +90 -0
- package/src/helpers/array/array_replace.mjs +25 -0
- package/src/helpers/array/array_replace_recursive.mjs +109 -0
- package/src/helpers/array/array_reverse.mjs +62 -0
- package/src/helpers/array/array_search.mjs +104 -0
- package/src/helpers/array/array_shift.mjs +78 -0
- package/src/helpers/array/array_slice.mjs +99 -0
- package/src/helpers/array/array_splice.mjs +218 -0
- package/src/helpers/array/array_sum.mjs +60 -0
- package/src/helpers/array/array_udiff.mjs +91 -0
- package/src/helpers/array/array_udiff_assoc.mjs +71 -0
- package/src/helpers/array/array_udiff_uassoc.mjs +124 -0
- package/src/helpers/array/array_uintersect.mjs +72 -0
- package/src/helpers/array/array_uintersect_assoc.mjs +77 -0
- package/src/helpers/array/array_uintersect_uassoc.mjs +121 -0
- package/src/helpers/array/array_unique.mjs +77 -0
- package/src/helpers/array/array_unshift.mjs +64 -0
- package/src/helpers/array/array_values.mjs +57 -0
- package/src/helpers/array/array_walk.mjs +95 -0
- package/src/helpers/array/array_walk_recursive.mjs +104 -0
- package/src/helpers/array/count.mjs +57 -0
- package/src/helpers/array/in_array.mjs +67 -0
- package/src/helpers/array/natsort.mjs +62 -0
- package/src/helpers/array/range.mjs +121 -0
- package/src/helpers/array/shuffle.mjs +73 -0
- package/src/helpers/array/sort.mjs +69 -0
- package/src/helpers/expect.mjs +44 -0
- package/src/helpers/expect_array.mjs +66 -0
- package/src/helpers/expect_assoc.mjs +66 -0
- package/src/helpers/expect_bigint.mjs +66 -0
- package/src/helpers/expect_bool.mjs +66 -0
- package/src/helpers/expect_boolean.mjs +57 -0
- package/src/helpers/expect_char.mjs +66 -0
- package/src/helpers/expect_class.mjs +66 -0
- package/src/helpers/expect_float.mjs +66 -0
- package/src/helpers/expect_function.mjs +66 -0
- package/src/helpers/expect_infinity.mjs +66 -0
- package/src/helpers/expect_int.mjs +66 -0
- package/src/helpers/expect_integer.mjs +57 -0
- package/src/helpers/expect_list.mjs +66 -0
- package/src/helpers/expect_nan.mjs +66 -0
- package/src/helpers/expect_null.mjs +66 -0
- package/src/helpers/expect_number.mjs +66 -0
- package/src/helpers/expect_numeric.mjs +66 -0
- package/src/helpers/expect_object.mjs +67 -0
- package/src/helpers/expect_scalar.mjs +66 -0
- package/src/helpers/expect_string.mjs +65 -0
- package/src/helpers/expect_symbol.mjs +66 -0
- package/src/helpers/expect_undefined.mjs +66 -0
- package/src/helpers/is_char.mjs +54 -0
- package/src/helpers/is_equal.mjs +94 -0
- package/src/helpers/string/is_digit_char.mjs +60 -0
- package/src/helpers/string/is_whitespace_char.mjs +54 -0
- package/src/helpers/string/natcompare.mjs +107 -0
- package/src/helpers/string/natcompare_numeric.mjs +131 -0
- package/tests/classes/Expect/toBe.test.mjs +60 -0
- package/tests/classes/Expect/toBeArray.test.mjs +46 -0
- package/tests/classes/Expect/toBeAssoc.test.mjs +48 -0
- package/tests/classes/Expect/toBeBigInt.test.mjs +46 -0
- package/tests/classes/Expect/toBeBool.test.mjs +48 -0
- package/tests/classes/Expect/toBeBoolean.test.mjs +48 -0
- package/tests/classes/Expect/toBeChar.test.mjs +46 -0
- package/tests/classes/Expect/toBeClass.test.mjs +48 -0
- package/tests/classes/Expect/toBeFloat.test.mjs +48 -0
- package/tests/classes/Expect/toBeFunction.test.mjs +51 -0
- package/tests/classes/Expect/toBeInfinity.test.mjs +48 -0
- package/tests/classes/Expect/toBeInt.test.mjs +48 -0
- package/tests/classes/Expect/toBeInteger.test.mjs +48 -0
- package/tests/classes/Expect/toBeList.test.mjs +46 -0
- package/tests/classes/Expect/toBeNaN.test.mjs +46 -0
- package/tests/classes/Expect/toBeNull.test.mjs +46 -0
- package/tests/classes/Expect/toBeNumber.test.mjs +46 -0
- package/tests/classes/Expect/toBeNumeric.test.mjs +53 -0
- package/tests/classes/Expect/toBeObject.test.mjs +47 -0
- package/tests/classes/Expect/toBeScalar.test.mjs +63 -0
- package/tests/classes/Expect/toBeString.test.mjs +46 -0
- package/tests/classes/Expect/toBeSymbol.test.mjs +46 -0
- package/tests/classes/Expect/toBeUndefined.test.mjs +50 -0
- package/tests/classes/Expect/toEqual.test.mjs +66 -0
- package/tests/classes/Expect/toStrictEqual.test.mjs +73 -0
- package/tests/classes/Type.test.mjs +1320 -1262
- package/tests/helpers/array/array_chunk.test.mjs +49 -0
- package/tests/helpers/array/array_chunk_with_keys.test.mjs +45 -0
- package/tests/helpers/array/array_column.test.mjs +87 -0
- package/tests/helpers/array/array_combine.test.mjs +41 -0
- package/tests/helpers/array/array_count_values.test.mjs +40 -0
- package/tests/helpers/array/array_diff.test.mjs +78 -0
- package/tests/helpers/array/array_diff_assoc.test.mjs +64 -0
- package/tests/helpers/array/array_diff_key.test.mjs +64 -0
- package/tests/helpers/array/array_diff_uassoc.test.mjs +73 -0
- package/tests/helpers/array/array_diff_ukey.test.mjs +77 -0
- package/tests/helpers/array/array_fill.test.mjs +47 -0
- package/tests/helpers/array/array_fill_keys.test.mjs +35 -0
- package/tests/helpers/array/array_filter.test.mjs +38 -0
- package/tests/helpers/array/array_flip.test.mjs +33 -0
- package/tests/helpers/array/array_index_max.test.mjs +41 -0
- package/tests/helpers/array/array_index_min.test.mjs +41 -0
- package/tests/helpers/array/array_intersect.test.mjs +65 -0
- package/tests/helpers/array/array_intersect_assoc.test.mjs +65 -0
- package/tests/helpers/array/array_intersect_key.test.mjs +65 -0
- package/tests/helpers/array/array_intersect_uassoc.test.mjs +76 -0
- package/tests/helpers/array/array_intersect_ukey.test.mjs +74 -0
- package/tests/helpers/array/array_key_exists.test.mjs +36 -0
- package/tests/helpers/array/array_key_first.test.mjs +29 -0
- package/tests/helpers/array/array_key_last.test.mjs +29 -0
- package/tests/helpers/array/array_key_to_lower_case.test.mjs +23 -0
- package/tests/helpers/array/array_key_to_upper_case.test.mjs +23 -0
- package/tests/helpers/array/array_keys.test.mjs +27 -0
- package/tests/helpers/array/array_map.test.mjs +32 -0
- package/tests/helpers/array/array_merge.test.mjs +37 -0
- package/tests/helpers/array/array_merge_recursive.test.mjs +65 -0
- package/tests/helpers/array/array_pad.test.mjs +48 -0
- package/tests/helpers/array/array_pop.test.mjs +29 -0
- package/tests/helpers/array/array_product.test.mjs +33 -0
- package/tests/helpers/array/array_push.test.mjs +31 -0
- package/tests/helpers/array/array_rand.test.mjs +59 -0
- package/tests/helpers/array/array_reduce.test.mjs +44 -0
- package/tests/helpers/array/array_replace.test.mjs +46 -0
- package/tests/helpers/array/array_replace_recursive.test.mjs +46 -0
- package/tests/helpers/array/array_reverse.test.mjs +31 -0
- package/tests/helpers/array/array_search.test.mjs +48 -0
- package/tests/helpers/array/array_shift.test.mjs +29 -0
- package/tests/helpers/array/array_slice.test.mjs +49 -0
- package/tests/helpers/array/array_splice.test.mjs +67 -0
- package/tests/helpers/array/array_sum.test.mjs +27 -0
- package/tests/helpers/array/array_udiff.test.mjs +95 -0
- package/tests/helpers/array/array_udiff_assoc.test.mjs +77 -0
- package/tests/helpers/array/array_udiff_uassoc.test.mjs +89 -0
- package/tests/helpers/array/array_uintersect.test.mjs +78 -0
- package/tests/helpers/array/array_uintersect_assoc.test.mjs +80 -0
- package/tests/helpers/array/array_uintersect_uassoc.test.mjs +122 -0
- package/tests/helpers/array/array_unique.test.mjs +27 -0
- package/tests/helpers/array/array_unshift.test.mjs +31 -0
- package/tests/helpers/array/array_values.test.mjs +27 -0
- package/tests/helpers/array/array_walk.test.mjs +48 -0
- package/tests/helpers/array/array_walk_recursive.test.mjs +53 -0
- package/tests/helpers/array/count.test.mjs +27 -0
- package/tests/helpers/array/in_array.test.mjs +52 -0
- package/tests/helpers/array/natsort.test.mjs +71 -0
- package/tests/helpers/array/range.test.mjs +51 -0
- package/tests/helpers/array/shuffle.test.mjs +42 -0
- package/tests/helpers/array/sort.test.mjs +60 -0
- package/tests/helpers/array.test.mjs +58 -58
- package/tests/helpers/expect.test.mjs +95 -0
- package/tests/helpers/expect_array.test.mjs +71 -0
- package/tests/helpers/expect_assoc.test.mjs +61 -0
- package/tests/helpers/expect_bigint.test.mjs +63 -0
- package/tests/helpers/expect_bool.test.mjs +59 -0
- package/tests/helpers/expect_boolean.test.mjs +61 -0
- package/tests/helpers/expect_char.test.mjs +63 -0
- package/tests/helpers/expect_class.test.mjs +64 -0
- package/tests/helpers/expect_float.test.mjs +64 -0
- package/tests/helpers/expect_function.test.mjs +65 -0
- package/tests/helpers/expect_infinity.test.mjs +62 -0
- package/tests/helpers/expect_int.test.mjs +57 -0
- package/tests/helpers/expect_integer.test.mjs +59 -0
- package/tests/helpers/expect_list.test.mjs +73 -0
- package/tests/helpers/expect_nan.test.mjs +57 -0
- package/tests/helpers/expect_null.test.mjs +57 -0
- package/tests/helpers/expect_number.test.mjs +57 -0
- package/tests/helpers/expect_numeric.test.mjs +57 -0
- package/tests/helpers/expect_object.test.mjs +63 -0
- package/tests/helpers/expect_scalar.test.mjs +72 -0
- package/tests/helpers/expect_string.test.mjs +65 -0
- package/tests/helpers/expect_symbol.test.mjs +66 -0
- package/tests/helpers/expect_undefined.test.mjs +59 -0
- package/tests/helpers/is_char.test.mjs +40 -0
- package/tests/helpers/is_equal.test.mjs +110 -0
- package/tests/helpers/string/is_digit_char.test.mjs +32 -0
- package/tests/helpers/string/is_whitespace_char.test.mjs +32 -0
- package/tests/helpers/string/natcompare.test.mjs +100 -0
- package/tests/helpers/string/natcompare_numeric.test.mjs +110 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_fill } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_fill', () => {
|
5
|
+
test('Должна заполнять пустой массив значениями', () => {
|
6
|
+
const result = array_fill([], 0, 3, 'a');
|
7
|
+
expect(result).toEqual(['a', 'a', 'a']);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должна заполнять массив значениями с указанного индекса', () => {
|
11
|
+
const result = array_fill([], 2, 3, 'b');
|
12
|
+
expect(result).toEqual([undefined, undefined, 'b', 'b', 'b']);
|
13
|
+
});
|
14
|
+
|
15
|
+
test('Должна заполнять существующий массив значениями', () => {
|
16
|
+
const existingArray = [1, 2, 3];
|
17
|
+
const result = array_fill(existingArray, 1, 2, 'c');
|
18
|
+
expect(result).toEqual([1, 'c', 'c']);
|
19
|
+
});
|
20
|
+
|
21
|
+
test('Должна выбрасывать ошибку при отрицательном значении для count', () => {
|
22
|
+
expect(() => array_fill([], 0, -1, 'd')).toThrow(TypeError);
|
23
|
+
expect(() => array_fill([], 0, -1, 'd')).toThrow(
|
24
|
+
'Параметр "count" должен быть равен или больше нуля.',
|
25
|
+
);
|
26
|
+
});
|
27
|
+
|
28
|
+
test('Должна выбрасывать ошибку при значении start_index, не являющемся целым числом', () => {
|
29
|
+
expect(() => array_fill([], 0.5, 3, 'e')).toThrow(TypeError);
|
30
|
+
expect(() => array_fill([], 0.5, 3, 'e')).toThrow(
|
31
|
+
'Параметр "start_index" должен быть целым числом.',
|
32
|
+
);
|
33
|
+
});
|
34
|
+
|
35
|
+
test('Должна заполнять ассоциативный массив значениями', () => {
|
36
|
+
const assocArray = { a: 1, b: 2 };
|
37
|
+
const result = array_fill(assocArray, 2, 3, 'f');
|
38
|
+
expect(result).toEqual({ a: 1, b: 2, 2: 'f', 3: 'f', 4: 'f' });
|
39
|
+
});
|
40
|
+
|
41
|
+
test('Должна выбрасывать ошибку, если arr не является массивом', () => {
|
42
|
+
expect(() => array_fill('not an array', 0, 3, 'g')).toThrow(TypeError);
|
43
|
+
expect(() => array_fill('not an array', 0, 3, 'g')).toThrow(
|
44
|
+
'Параметр "arr" должен быть массивом.',
|
45
|
+
);
|
46
|
+
});
|
47
|
+
});
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_fill_keys } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_fill_keys', () => {
|
5
|
+
test('Должна заполнять пустой массив значениями по ключам', () => {
|
6
|
+
const result = array_fill_keys([], [0, 1, 2], 'a');
|
7
|
+
expect(result).toEqual(['a', 'a', 'a']);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должна заполнять существующий массив значениями по ключам', () => {
|
11
|
+
const existingArray = [1, 2, 3];
|
12
|
+
const result = array_fill_keys(existingArray, [1, 2], 'b');
|
13
|
+
expect(result).toEqual([1, 'b', 'b']);
|
14
|
+
});
|
15
|
+
|
16
|
+
test('Должна заполнять ассоциативный массив значениями по ключам', () => {
|
17
|
+
const assocArray = { a: 1, b: 2 };
|
18
|
+
const result = array_fill_keys(assocArray, ['c', 'd'], 'c');
|
19
|
+
expect(result).toEqual({ a: 1, b: 2, c: 'c', d: 'c' });
|
20
|
+
});
|
21
|
+
|
22
|
+
test('Должна выбрасывать ошибку, если arr не является массивом', () => {
|
23
|
+
expect(() => array_fill_keys('not an array', [0, 1, 2], 'd')).toThrow(TypeError);
|
24
|
+
expect(() => array_fill_keys('not an array', [0, 1, 2], 'd')).toThrow(
|
25
|
+
'Параметр "arr" должен быть массивом.',
|
26
|
+
);
|
27
|
+
});
|
28
|
+
|
29
|
+
test('Должна выбрасывать ошибку, если keys не является списком', () => {
|
30
|
+
expect(() => array_fill_keys([], 'not a list', 'e')).toThrow(TypeError);
|
31
|
+
expect(() => array_fill_keys([], 'not a list', 'e')).toThrow(
|
32
|
+
'Параметр "keys" должен быть списком.',
|
33
|
+
);
|
34
|
+
});
|
35
|
+
});
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_filter } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_filter', () => {
|
5
|
+
test('Должна фильтровать массив с использованием функции обратного вызова', () => {
|
6
|
+
const array = [1, 2, 3, 4, 5];
|
7
|
+
const callback = (value) => value > 2;
|
8
|
+
const result = array_filter(array, callback);
|
9
|
+
expect(result).toEqual([3, 4, 5]);
|
10
|
+
});
|
11
|
+
|
12
|
+
test('Должна фильтровать массив без функции обратного вызова (удаление пустых значений)', () => {
|
13
|
+
const array = [0, 1, false, 2, '', 3];
|
14
|
+
const result = array_filter(array);
|
15
|
+
expect(result).toEqual([1, 2, 3]);
|
16
|
+
});
|
17
|
+
|
18
|
+
test('Должна фильтровать ассоциативный массив с использованием функции обратного вызова', () => {
|
19
|
+
const array = { a: 1, b: 2, c: 3, d: 4 };
|
20
|
+
const callback = (value) => value > 2;
|
21
|
+
const result = array_filter(array, callback);
|
22
|
+
expect(result).toEqual({ c: 3, d: 4 });
|
23
|
+
});
|
24
|
+
|
25
|
+
test('Должна выбрасывать ошибку, если value не является массивом', () => {
|
26
|
+
expect(() => array_filter('not an array')).toThrow(TypeError);
|
27
|
+
expect(() => array_filter('not an array')).toThrow(
|
28
|
+
'Параметр "value" должен быть массивом.',
|
29
|
+
);
|
30
|
+
});
|
31
|
+
|
32
|
+
test('Должна выбрасывать ошибку, если callback не является функцией', () => {
|
33
|
+
expect(() => array_filter([1, 2, 3], 'not a function')).toThrow(TypeError);
|
34
|
+
expect(() => array_filter([1, 2, 3], 'not a function')).toThrow(
|
35
|
+
'Параметр "callback" должен быть функцией.',
|
36
|
+
);
|
37
|
+
});
|
38
|
+
});
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_flip } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_flip', () => {
|
5
|
+
test('Должна менять местами ключи и значения в обычном массиве', () => {
|
6
|
+
const array = { a: 1, b: 2, c: 3 };
|
7
|
+
const result = array_flip(array);
|
8
|
+
expect(result).toEqual({ 1: 'a', 2: 'b', 3: 'c' });
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна обрабатывать пустой массив', () => {
|
12
|
+
const array = {};
|
13
|
+
const result = array_flip(array);
|
14
|
+
expect(result).toEqual({});
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна выбрасывать ошибку, если value не является массивом', () => {
|
18
|
+
expect(() => array_flip('not an array')).toThrow(TypeError);
|
19
|
+
expect(() => array_flip('not an array')).toThrow('Параметр "value" должен быть массивом.');
|
20
|
+
});
|
21
|
+
|
22
|
+
test('Должна корректно обрабатывать массив с повторяющимися значениями', () => {
|
23
|
+
const array = { a: 1, b: 1, c: 2 };
|
24
|
+
const result = array_flip(array);
|
25
|
+
expect(result).toEqual({ 1: 'b', 2: 'c' });
|
26
|
+
});
|
27
|
+
|
28
|
+
test('Должна корректно обрабатывать массив с различными типами данных', () => {
|
29
|
+
const array = { a: 1, b: '2', c: true };
|
30
|
+
const result = array_flip(array);
|
31
|
+
expect(result).toEqual({ 1: 'a', 2: 'b', true: 'c' });
|
32
|
+
});
|
33
|
+
});
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_index_max } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_index_max', () => {
|
5
|
+
test('Должна возвращать максимальный индекс обычного массива', () => {
|
6
|
+
const array = [1, 2, 3];
|
7
|
+
const result = array_index_max(array);
|
8
|
+
expect(result).toBe(2);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна возвращать null для ассоциативного массива без числовых ключей', () => {
|
12
|
+
const array = { a: 1, b: 2, c: 3 };
|
13
|
+
const result = array_index_max(array);
|
14
|
+
expect(result).toBeNull();
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна возвращать максимальный числовой ключ для ассоциативного массива с числовыми ключами', () => {
|
18
|
+
const array = { a: 1, 2: 'b', 3: 'c' };
|
19
|
+
const result = array_index_max(array);
|
20
|
+
expect(result).toBe(3);
|
21
|
+
});
|
22
|
+
|
23
|
+
test('Должна возвращать null для пустого массива', () => {
|
24
|
+
const array = [];
|
25
|
+
const result = array_index_max(array);
|
26
|
+
expect(result).toBeNull();
|
27
|
+
});
|
28
|
+
|
29
|
+
test('Должна выбрасывать ошибку, если value не является массивом', () => {
|
30
|
+
expect(() => array_index_max('not an array')).toThrow(TypeError);
|
31
|
+
expect(() => array_index_max('not an array')).toThrow(
|
32
|
+
'Параметр "value" должен быть массивом.',
|
33
|
+
);
|
34
|
+
});
|
35
|
+
|
36
|
+
test('Должна корректно обрабатывать массив с различными типами данных', () => {
|
37
|
+
const array = { a: 1, b: '2', 3: true };
|
38
|
+
const result = array_index_max(array);
|
39
|
+
expect(result).toBe(3);
|
40
|
+
});
|
41
|
+
});
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_index_min } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_index_min', () => {
|
5
|
+
test('Должна возвращать минимальный индекс обычного массива', () => {
|
6
|
+
const array = [1, 2, 3];
|
7
|
+
const result = array_index_min(array);
|
8
|
+
expect(result).toBe(0);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна возвращать null для ассоциативного массива без числовых ключей', () => {
|
12
|
+
const array = { a: 1, b: 2, c: 3 };
|
13
|
+
const result = array_index_min(array);
|
14
|
+
expect(result).toBeNull();
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна возвращать минимальный числовой ключ для ассоциативного массива с числовыми ключами', () => {
|
18
|
+
const array = { 1: 'a', 2: 'b', 3: 'c' };
|
19
|
+
const result = array_index_min(array);
|
20
|
+
expect(result).toBe(1);
|
21
|
+
});
|
22
|
+
|
23
|
+
test('Должна возвращать null для пустого массива', () => {
|
24
|
+
const array = [];
|
25
|
+
const result = array_index_min(array);
|
26
|
+
expect(result).toBeNull();
|
27
|
+
});
|
28
|
+
|
29
|
+
test('Должна выбрасывать ошибку, если value не является массивом', () => {
|
30
|
+
expect(() => array_index_min('not an array')).toThrow(TypeError);
|
31
|
+
expect(() => array_index_min('not an array')).toThrow(
|
32
|
+
'Параметр "value" должен быть массивом.',
|
33
|
+
);
|
34
|
+
});
|
35
|
+
|
36
|
+
test('Должна корректно обрабатывать массив с различными типами данных', () => {
|
37
|
+
const array = { a: 1, b: '2', 3: true };
|
38
|
+
const result = array_index_min(array);
|
39
|
+
expect(result).toBe(3);
|
40
|
+
});
|
41
|
+
});
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_intersect } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_intersect', () => {
|
5
|
+
test('Должна возвращать элементы из первого массива, которые присутствуют в других массивах', () => {
|
6
|
+
const original_array = { a: 1, b: 2, c: 3 };
|
7
|
+
const array1 = { a: 1, b: 2 };
|
8
|
+
const array2 = { b: 2, c: 3 };
|
9
|
+
const result = array_intersect(original_array, array1, array2);
|
10
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
11
|
+
});
|
12
|
+
|
13
|
+
test('Должна возвращать пустой объект, если все элементы первого массива отсутствуют в других массивах', () => {
|
14
|
+
const original_array = { a: 1, b: 2 };
|
15
|
+
const array1 = { c: 3, d: 4 };
|
16
|
+
const result = array_intersect(original_array, array1);
|
17
|
+
expect(result).toEqual({});
|
18
|
+
});
|
19
|
+
|
20
|
+
test('Должна корректно обрабатывать пустые массивы', () => {
|
21
|
+
const original_array = {};
|
22
|
+
const array1 = {};
|
23
|
+
const result = array_intersect(original_array, array1);
|
24
|
+
expect(result).toEqual({});
|
25
|
+
});
|
26
|
+
|
27
|
+
test('Должна выбрасывать ошибку, если переданное значение для original_array не является массивом', () => {
|
28
|
+
expect(() => array_intersect('not an array')).toThrow(TypeError);
|
29
|
+
expect(() => array_intersect('not an array')).toThrow(
|
30
|
+
'Параметр "original_array" должен быть массивом.',
|
31
|
+
);
|
32
|
+
});
|
33
|
+
|
34
|
+
test('Должна выбрасывать ошибку, если переданное значение для arrays не является массивом', () => {
|
35
|
+
expect(() => array_intersect({}, 'not an array')).toThrow(TypeError);
|
36
|
+
expect(() => array_intersect({}, 'not an array')).toThrow(
|
37
|
+
'Параметр "arrays" должен быть массивом.',
|
38
|
+
);
|
39
|
+
});
|
40
|
+
|
41
|
+
test('Должна корректно обрабатывать массивы с различными типами данных', () => {
|
42
|
+
const original_array = { a: 1, b: '2', c: true };
|
43
|
+
const array1 = { a: 1, b: 2, d: false };
|
44
|
+
const result = array_intersect(original_array, array1);
|
45
|
+
expect(result).toEqual({ a: 1 });
|
46
|
+
});
|
47
|
+
|
48
|
+
test('Должна корректно обрабатывать несколько массивов для сравнения', () => {
|
49
|
+
const original_array = { a: 1, b: 2, c: 3, d: 4 };
|
50
|
+
const array1 = { a: 1, b: 2 };
|
51
|
+
const array2 = { c: 3 };
|
52
|
+
const result = array_intersect(original_array, array1, array2);
|
53
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
54
|
+
});
|
55
|
+
|
56
|
+
test('Должна корректно обрабатывать массивы с вложенными структурами', () => {
|
57
|
+
const original_array = {
|
58
|
+
a: { id: 1, data: [1, 2] },
|
59
|
+
b: { id: 2, data: [3, 4] },
|
60
|
+
};
|
61
|
+
const array1 = { a: { id: 1, data: [1, 2] } };
|
62
|
+
const result = array_intersect(original_array, array1);
|
63
|
+
expect(result).toEqual({ a: { id: 1, data: [1, 2] } });
|
64
|
+
});
|
65
|
+
});
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_intersect_assoc } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_intersect_assoc', () => {
|
5
|
+
test('Должна возвращать элементы из первого массива, которые присутствуют в других массивах', () => {
|
6
|
+
const original_array = { a: 1, b: 2, c: 3 };
|
7
|
+
const array1 = { a: 1, b: 2 };
|
8
|
+
const array2 = { b: 2, c: 3 };
|
9
|
+
const result = array_intersect_assoc(original_array, array1, array2);
|
10
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
11
|
+
});
|
12
|
+
|
13
|
+
test('Должна возвращать пустой объект, если все элементы первого массива отсутствуют в других массивах', () => {
|
14
|
+
const original_array = { a: 1, b: 2 };
|
15
|
+
const array1 = { c: 3, d: 4 };
|
16
|
+
const result = array_intersect_assoc(original_array, array1);
|
17
|
+
expect(result).toEqual({});
|
18
|
+
});
|
19
|
+
|
20
|
+
test('Должна корректно обрабатывать пустые массивы', () => {
|
21
|
+
const original_array = {};
|
22
|
+
const array1 = {};
|
23
|
+
const result = array_intersect_assoc(original_array, array1);
|
24
|
+
expect(result).toEqual({});
|
25
|
+
});
|
26
|
+
|
27
|
+
test('Должна выбрасывать ошибку, если переданное значение для original_array не является массивом', () => {
|
28
|
+
expect(() => array_intersect_assoc('not an array')).toThrow(TypeError);
|
29
|
+
expect(() => array_intersect_assoc('not an array')).toThrow(
|
30
|
+
'Параметр "original_array" должен быть массивом.',
|
31
|
+
);
|
32
|
+
});
|
33
|
+
|
34
|
+
test('Должна выбрасывать ошибку, если переданное значение для arrays не является массивом', () => {
|
35
|
+
expect(() => array_intersect_assoc({}, 'not an array')).toThrow(TypeError);
|
36
|
+
expect(() => array_intersect_assoc({}, 'not an array')).toThrow(
|
37
|
+
'Параметр "arrays" должен быть массивом.',
|
38
|
+
);
|
39
|
+
});
|
40
|
+
|
41
|
+
test('Должна корректно обрабатывать массивы с различными типами данных', () => {
|
42
|
+
const original_array = { a: 1, b: '2', c: true };
|
43
|
+
const array1 = { a: 1, b: 2, d: false };
|
44
|
+
const result = array_intersect_assoc(original_array, array1);
|
45
|
+
expect(result).toEqual({ a: 1 });
|
46
|
+
});
|
47
|
+
|
48
|
+
test('Должна корректно обрабатывать несколько массивов для сравнения', () => {
|
49
|
+
const original_array = { a: 1, b: 2, c: 3, d: 4 };
|
50
|
+
const array1 = { a: 1, b: 2 };
|
51
|
+
const array2 = { c: 3 };
|
52
|
+
const result = array_intersect_assoc(original_array, array1, array2);
|
53
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
54
|
+
});
|
55
|
+
|
56
|
+
test('Должна корректно обрабатывать массивы с вложенными структурами', () => {
|
57
|
+
const original_array = {
|
58
|
+
a: { id: 1, data: [1, 2] },
|
59
|
+
b: { id: 2, data: [3, 4] },
|
60
|
+
};
|
61
|
+
const array1 = { a: { id: 1, data: [1, 2] } };
|
62
|
+
const result = array_intersect_assoc(original_array, array1);
|
63
|
+
expect(result).toEqual({ a: { id: 1, data: [1, 2] } });
|
64
|
+
});
|
65
|
+
});
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_intersect_key } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_intersect_key', () => {
|
5
|
+
test('Должна возвращать элементы из первого массива, которые присутствуют в других массивах', () => {
|
6
|
+
const original_array = { a: 1, b: 2, c: 3 };
|
7
|
+
const array1 = { a: 1, b: 2 };
|
8
|
+
const array2 = { b: 2, c: 3 };
|
9
|
+
const result = array_intersect_key(original_array, array1, array2);
|
10
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
11
|
+
});
|
12
|
+
|
13
|
+
test('Должна возвращать пустой объект, если все элементы первого массива отсутствуют в других массивах', () => {
|
14
|
+
const original_array = { a: 1, b: 2 };
|
15
|
+
const array1 = { c: 3, d: 4 };
|
16
|
+
const result = array_intersect_key(original_array, array1);
|
17
|
+
expect(result).toEqual({});
|
18
|
+
});
|
19
|
+
|
20
|
+
test('Должна корректно обрабатывать пустые массивы', () => {
|
21
|
+
const original_array = {};
|
22
|
+
const array1 = {};
|
23
|
+
const result = array_intersect_key(original_array, array1);
|
24
|
+
expect(result).toEqual({});
|
25
|
+
});
|
26
|
+
|
27
|
+
test('Должна выбрасывать ошибку, если переданное значение для original_array не является массивом', () => {
|
28
|
+
expect(() => array_intersect_key('not an array')).toThrow(TypeError);
|
29
|
+
expect(() => array_intersect_key('not an array')).toThrow(
|
30
|
+
'Параметр "original_array" должен быть массивом.',
|
31
|
+
);
|
32
|
+
});
|
33
|
+
|
34
|
+
test('Должна выбрасывать ошибку, если переданное значение для arrays не является массивом', () => {
|
35
|
+
expect(() => array_intersect_key({}, 'not an array')).toThrow(TypeError);
|
36
|
+
expect(() => array_intersect_key({}, 'not an array')).toThrow(
|
37
|
+
'Параметр "arrays" должен быть массивом.',
|
38
|
+
);
|
39
|
+
});
|
40
|
+
|
41
|
+
test('Должна корректно обрабатывать массивы с различными типами данных', () => {
|
42
|
+
const original_array = { a: 1, b: '2', c: true };
|
43
|
+
const array1 = { a: 1, b: 2, d: false };
|
44
|
+
const result = array_intersect_key(original_array, array1);
|
45
|
+
expect(result).toEqual({ a: 1, b: '2' });
|
46
|
+
});
|
47
|
+
|
48
|
+
test('Должна корректно обрабатывать несколько массивов для сравнения', () => {
|
49
|
+
const original_array = { a: 1, b: 2, c: 3, d: 4 };
|
50
|
+
const array1 = { a: 1, b: 2 };
|
51
|
+
const array2 = { c: 3 };
|
52
|
+
const result = array_intersect_key(original_array, array1, array2);
|
53
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
54
|
+
});
|
55
|
+
|
56
|
+
test('Должна корректно обрабатывать массивы с вложенными структурами', () => {
|
57
|
+
const original_array = {
|
58
|
+
a: { id: 1, data: [1, 2] },
|
59
|
+
b: { id: 2, data: [3, 4] },
|
60
|
+
};
|
61
|
+
const array1 = { a: { id: 1, data: [1, 2] } };
|
62
|
+
const result = array_intersect_key(original_array, array1);
|
63
|
+
expect(result).toEqual({ a: { id: 1, data: [1, 2] } });
|
64
|
+
});
|
65
|
+
});
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_intersect_uassoc } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_intersect_uassoc', () => {
|
5
|
+
const key_compare_func = (a, b) => a === b;
|
6
|
+
|
7
|
+
test('Должна возвращать элементы из первого массива, которые присутствуют в других массивах', () => {
|
8
|
+
const original_array = { a: 1, b: 2, c: 3 };
|
9
|
+
const array1 = { a: 1, b: 2 };
|
10
|
+
const array2 = { b: 2, c: 3 };
|
11
|
+
const result = array_intersect_uassoc(key_compare_func, original_array, array1, array2);
|
12
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
13
|
+
});
|
14
|
+
|
15
|
+
test('Должна возвращать пустой объект, если все элементы первого массива отсутствуют в других массивах', () => {
|
16
|
+
const original_array = { a: 1, b: 2 };
|
17
|
+
const array1 = { c: 3, d: 4 };
|
18
|
+
const result = array_intersect_uassoc(key_compare_func, original_array, array1);
|
19
|
+
expect(result).toEqual({});
|
20
|
+
});
|
21
|
+
|
22
|
+
test('Должна корректно обрабатывать пустые массивы', () => {
|
23
|
+
const original_array = {};
|
24
|
+
const array1 = {};
|
25
|
+
const result = array_intersect_uassoc(key_compare_func, original_array, array1);
|
26
|
+
expect(result).toEqual({});
|
27
|
+
});
|
28
|
+
|
29
|
+
test('Должна выбрасывать ошибку, если переданное значение для key_compare_func не является функцией', () => {
|
30
|
+
expect(() => array_intersect_uassoc('not a function', {})).toThrow(TypeError);
|
31
|
+
expect(() => array_intersect_uassoc('not a function', {})).toThrow(
|
32
|
+
'Параметр "key_compare_func" должен быть функцией.',
|
33
|
+
);
|
34
|
+
});
|
35
|
+
|
36
|
+
test('Должна выбрасывать ошибку, если переданное значение для original_array не является массивом', () => {
|
37
|
+
expect(() => array_intersect_uassoc(key_compare_func, 'not an array')).toThrow(TypeError);
|
38
|
+
expect(() => array_intersect_uassoc(key_compare_func, 'not an array')).toThrow(
|
39
|
+
'Параметр "original_array" должен быть массивом.',
|
40
|
+
);
|
41
|
+
});
|
42
|
+
|
43
|
+
test('Должна выбрасывать ошибку, если переданное значение для arrays не является массивом', () => {
|
44
|
+
expect(() => array_intersect_uassoc(key_compare_func, {}, 'not an array')).toThrow(
|
45
|
+
TypeError,
|
46
|
+
);
|
47
|
+
expect(() => array_intersect_uassoc(key_compare_func, {}, 'not an array')).toThrow(
|
48
|
+
'Параметр "arrays" должен быть массивом.',
|
49
|
+
);
|
50
|
+
});
|
51
|
+
|
52
|
+
test('Должна корректно обрабатывать массивы с различными типами данных', () => {
|
53
|
+
const original_array = { a: 1, b: '2', c: true };
|
54
|
+
const array1 = { a: 1, b: 2, d: false };
|
55
|
+
const result = array_intersect_uassoc(key_compare_func, original_array, array1);
|
56
|
+
expect(result).toEqual({ a: 1 });
|
57
|
+
});
|
58
|
+
|
59
|
+
test('Должна корректно обрабатывать несколько массивов для сравнения', () => {
|
60
|
+
const original_array = { a: 1, b: 2, c: 3, d: 4 };
|
61
|
+
const array1 = { a: 1, b: 2 };
|
62
|
+
const array2 = { c: 3 };
|
63
|
+
const result = array_intersect_uassoc(key_compare_func, original_array, array1, array2);
|
64
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
65
|
+
});
|
66
|
+
|
67
|
+
test('Должна корректно обрабатывать массивы с вложенными структурами', () => {
|
68
|
+
const original_array = {
|
69
|
+
a: { id: 1, data: [1, 2] },
|
70
|
+
b: { id: 2, data: [3, 4] },
|
71
|
+
};
|
72
|
+
const array1 = { a: { id: 1, data: [1, 2] } };
|
73
|
+
const result = array_intersect_uassoc(key_compare_func, original_array, array1);
|
74
|
+
expect(result).toEqual({ a: { id: 1, data: [1, 2] } });
|
75
|
+
});
|
76
|
+
});
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_intersect_ukey } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_intersect_ukey', () => {
|
5
|
+
const key_compare_func = (a, b) => a === b;
|
6
|
+
|
7
|
+
test('Должна возвращать элементы из первого массива, которые присутствуют в других массивах', () => {
|
8
|
+
const original_array = { a: 1, b: 2, c: 3 };
|
9
|
+
const array1 = { a: 1, b: 2 };
|
10
|
+
const array2 = { b: 2, c: 3 };
|
11
|
+
const result = array_intersect_ukey(key_compare_func, original_array, array1, array2);
|
12
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
13
|
+
});
|
14
|
+
|
15
|
+
test('Должна возвращать пустой объект, если все элементы первого массива отсутствуют в других массивах', () => {
|
16
|
+
const original_array = { a: 1, b: 2 };
|
17
|
+
const array1 = { c: 3, d: 4 };
|
18
|
+
const result = array_intersect_ukey(key_compare_func, original_array, array1);
|
19
|
+
expect(result).toEqual({});
|
20
|
+
});
|
21
|
+
|
22
|
+
test('Должна корректно обрабатывать пустые массивы', () => {
|
23
|
+
const original_array = {};
|
24
|
+
const array1 = {};
|
25
|
+
const result = array_intersect_ukey(key_compare_func, original_array, array1);
|
26
|
+
expect(result).toEqual({});
|
27
|
+
});
|
28
|
+
|
29
|
+
test('Должна выбрасывать ошибку, если переданное значение для key_compare_func не является функцией', () => {
|
30
|
+
expect(() => array_intersect_ukey('not a function', {})).toThrow(TypeError);
|
31
|
+
expect(() => array_intersect_ukey('not a function', {})).toThrow(
|
32
|
+
'Параметр "key_compare_func" должен быть функцией.',
|
33
|
+
);
|
34
|
+
});
|
35
|
+
|
36
|
+
test('Должна выбрасывать ошибку, если переданное значение для original_array не является массивом', () => {
|
37
|
+
expect(() => array_intersect_ukey(key_compare_func, 'not an array')).toThrow(TypeError);
|
38
|
+
expect(() => array_intersect_ukey(key_compare_func, 'not an array')).toThrow(
|
39
|
+
'Параметр "original_array" должен быть массивом.',
|
40
|
+
);
|
41
|
+
});
|
42
|
+
|
43
|
+
test('Должна выбрасывать ошибку, если переданное значение для arrays не является массивом', () => {
|
44
|
+
expect(() => array_intersect_ukey(key_compare_func, {}, 'not an array')).toThrow(TypeError);
|
45
|
+
expect(() => array_intersect_ukey(key_compare_func, {}, 'not an array')).toThrow(
|
46
|
+
'Параметр "arrays" должен быть массивом.',
|
47
|
+
);
|
48
|
+
});
|
49
|
+
|
50
|
+
test('Должна корректно обрабатывать массивы с различными типами данных', () => {
|
51
|
+
const original_array = { a: 1, b: '2', c: true };
|
52
|
+
const array1 = { a: 1, b: 2, d: false };
|
53
|
+
const result = array_intersect_ukey(key_compare_func, original_array, array1);
|
54
|
+
expect(result).toEqual({ a: 1, b: '2' });
|
55
|
+
});
|
56
|
+
|
57
|
+
test('Должна корректно обрабатывать несколько массивов для сравнения', () => {
|
58
|
+
const original_array = { a: 1, b: 2, c: 3, d: 4 };
|
59
|
+
const array1 = { a: 1, b: 2 };
|
60
|
+
const array2 = { c: 3 };
|
61
|
+
const result = array_intersect_ukey(key_compare_func, original_array, array1, array2);
|
62
|
+
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
63
|
+
});
|
64
|
+
|
65
|
+
test('Должна корректно обрабатывать массивы с вложенными структурами', () => {
|
66
|
+
const original_array = {
|
67
|
+
a: { id: 1, data: [1, 2] },
|
68
|
+
b: { id: 2, data: [3, 4] },
|
69
|
+
};
|
70
|
+
const array1 = { a: { id: 1, data: [1, 2] } };
|
71
|
+
const result = array_intersect_ukey(key_compare_func, original_array, array1);
|
72
|
+
expect(result).toEqual({ a: { id: 1, data: [1, 2] } });
|
73
|
+
});
|
74
|
+
});
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_key_exists } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_key_exists', () => {
|
5
|
+
test('Должна возвращать true, если ключ существует в обычном массиве', () => {
|
6
|
+
const array = [1, 2, 3];
|
7
|
+
const result = array_key_exists(array, 1);
|
8
|
+
expect(result).toBe(true);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна возвращать true, если ключ существует в ассоциативном массиве', () => {
|
12
|
+
const array = { a: 1, b: 2, c: 3 };
|
13
|
+
const result = array_key_exists(array, 'b');
|
14
|
+
expect(result).toBe(true);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна возвращать false, если ключ отсутствует в массиве', () => {
|
18
|
+
const array = [1, 2, 3];
|
19
|
+
const result = array_key_exists(array, 5);
|
20
|
+
expect(result).toBe(false);
|
21
|
+
});
|
22
|
+
|
23
|
+
test('Должна выбрасывать ошибку, если value не является массивом', () => {
|
24
|
+
expect(() => array_key_exists('not an array', 1)).toThrow(TypeError);
|
25
|
+
expect(() => array_key_exists('not an array', 1)).toThrow(
|
26
|
+
'Параметр "value" должен быть массивом.',
|
27
|
+
);
|
28
|
+
});
|
29
|
+
|
30
|
+
test('Должна выбрасывать ошибку, если key не является целым числом или строкой', () => {
|
31
|
+
expect(() => array_key_exists([1, 2, 3], {})).toThrow(TypeError);
|
32
|
+
expect(() => array_key_exists([1, 2, 3], {})).toThrow(
|
33
|
+
'Параметр "key" должен быть целым числом или строкой.',
|
34
|
+
);
|
35
|
+
});
|
36
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { array_key_first } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция array_key_first', () => {
|
5
|
+
test('Должна возвращать первый ключ обычного массива', () => {
|
6
|
+
const array = [1, 2, 3];
|
7
|
+
const result = array_key_first(array);
|
8
|
+
expect(result).toBe(0);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна возвращать первый ключ ассоциативного массива', () => {
|
12
|
+
const array = { a: 1, b: 2, c: 3 };
|
13
|
+
const result = array_key_first(array);
|
14
|
+
expect(result).toBe('a');
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна возвращать null для пустого массива', () => {
|
18
|
+
const array = [];
|
19
|
+
const result = array_key_first(array);
|
20
|
+
expect(result).toBeNull();
|
21
|
+
});
|
22
|
+
|
23
|
+
test('Должна выбрасывать ошибку, если value не является массивом', () => {
|
24
|
+
expect(() => array_key_first('not an array')).toThrow(TypeError);
|
25
|
+
expect(() => array_key_first('not an array')).toThrow(
|
26
|
+
'Параметр "value" должен быть массивом.',
|
27
|
+
);
|
28
|
+
});
|
29
|
+
});
|