@rogolev/value 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +142 -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/is_char.md +84 -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 +125 -1
- package/index.mjs +66 -1
- package/package.json +2 -1
- package/prettier.config.mjs +2 -1
- 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/is_char.mjs +54 -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/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/is_char.test.mjs +40 -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,71 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { natsort } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция natsort', () => {
|
5
|
+
test('Должна корректно сортировать обычный массив', () => {
|
6
|
+
const array = [10, 2, 30, 4];
|
7
|
+
const result = natsort(array);
|
8
|
+
expect(result).toEqual([2, 4, 10, 30]);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна корректно сортировать ассоциативный массив', () => {
|
12
|
+
const array = { a: 10, b: 2, c: 30, d: 4 };
|
13
|
+
const result = natsort(array);
|
14
|
+
expect(result).toEqual([
|
15
|
+
['b', 2],
|
16
|
+
['d', 4],
|
17
|
+
['a', 10],
|
18
|
+
['c', 30],
|
19
|
+
]);
|
20
|
+
});
|
21
|
+
|
22
|
+
test('Должна корректно сортировать массив с использованием функции getter', () => {
|
23
|
+
const array = [{ value: 10 }, { value: 2 }, { value: 30 }, { value: 4 }];
|
24
|
+
const result = natsort(array, (entry) => entry[1].value);
|
25
|
+
expect(result).toEqual([{ value: 2 }, { value: 4 }, { value: 10 }, { value: 30 }]);
|
26
|
+
});
|
27
|
+
|
28
|
+
test('Должна выбрасывать ошибку, если параметр getter не является функцией', () => {
|
29
|
+
const array = [10, 2, 30, 4];
|
30
|
+
expect(() => natsort(array, 'not a function')).toThrow(TypeError);
|
31
|
+
expect(() => natsort(array, 'not a function')).toThrow(
|
32
|
+
'Параметр "getter" должен быть функцией.',
|
33
|
+
);
|
34
|
+
});
|
35
|
+
|
36
|
+
test('Должна корректно сортировать массив строк', () => {
|
37
|
+
const array = ['apple', 'banana', 'cherry', 'date'];
|
38
|
+
const result = natsort(array);
|
39
|
+
expect(result).toEqual(['apple', 'banana', 'cherry', 'date']);
|
40
|
+
});
|
41
|
+
|
42
|
+
test('Должна корректно сортировать массив строк с числовыми значениями', () => {
|
43
|
+
const array = ['10', '2', '30', '4'];
|
44
|
+
const result = natsort(array);
|
45
|
+
expect(result).toEqual(['2', '4', '10', '30']);
|
46
|
+
});
|
47
|
+
|
48
|
+
test('Должна корректно сортировать массив строк с ведущими нулями', () => {
|
49
|
+
const array = ['0010', '010', '10', '001'];
|
50
|
+
const result = natsort(array);
|
51
|
+
expect(result).toEqual(['001', '0010', '010', '10']);
|
52
|
+
});
|
53
|
+
|
54
|
+
test('Должна корректно сортировать массив строк с пробелами', () => {
|
55
|
+
const array = [' 10', '10', ' 2', '2'];
|
56
|
+
const result = natsort(array);
|
57
|
+
expect(result).toEqual([' 2', '2', ' 10', '10']);
|
58
|
+
});
|
59
|
+
|
60
|
+
test('Должна корректно сортировать массив строк с буквами и числами', () => {
|
61
|
+
const array = ['a10', 'a2', 'b10', 'b2'];
|
62
|
+
const result = natsort(array);
|
63
|
+
expect(result).toEqual(['a2', 'a10', 'b2', 'b10']);
|
64
|
+
});
|
65
|
+
|
66
|
+
test('Должна корректно сортировать массив строк с разными символами', () => {
|
67
|
+
const array = ['10-', '10+', '10*', '10/'];
|
68
|
+
const result = natsort(array);
|
69
|
+
expect(result).toEqual(['10*', '10+', '10-', '10/']);
|
70
|
+
});
|
71
|
+
});
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { range } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция range', () => {
|
5
|
+
test('Должна генерировать числовой диапазон', () => {
|
6
|
+
const result = range(1, 5);
|
7
|
+
expect(result).toEqual([1, 2, 3, 4, 5]);
|
8
|
+
});
|
9
|
+
|
10
|
+
test('Должна генерировать числовой диапазон с отрицательным шагом', () => {
|
11
|
+
const result = range(5, 1, -1);
|
12
|
+
expect(result).toEqual([5, 4, 3, 2, 1]);
|
13
|
+
});
|
14
|
+
|
15
|
+
test('Должна генерировать диапазон строк', () => {
|
16
|
+
const result = range('a', 'e');
|
17
|
+
expect(result).toEqual(['a', 'b', 'c', 'd', 'e']);
|
18
|
+
});
|
19
|
+
|
20
|
+
test('Должна обрабатывать значения с преобразованием типов', () => {
|
21
|
+
const result = range('1', 5);
|
22
|
+
expect(result).toEqual([1, 2, 3, 4, 5]);
|
23
|
+
});
|
24
|
+
|
25
|
+
test('Должна выбрасывать ошибку, если параметр "start" имеет неверный тип', () => {
|
26
|
+
expect(() => range({}, 5)).toThrow(TypeError);
|
27
|
+
expect(() => range({}, 5)).toThrow('Параметр "start" должен быть строкой или числом.');
|
28
|
+
});
|
29
|
+
|
30
|
+
test('Должна выбрасывать ошибку, если параметр "end" имеет неверный тип', () => {
|
31
|
+
expect(() => range(1, {})).toThrow(TypeError);
|
32
|
+
expect(() => range(1, {})).toThrow('Параметр "end" должен быть строкой или числом.');
|
33
|
+
});
|
34
|
+
|
35
|
+
test('Должна выбрасывать ошибку, если параметр "step" имеет неверный тип', () => {
|
36
|
+
expect(() => range(1, 5, 'a')).toThrow(TypeError);
|
37
|
+
expect(() => range(1, 5, 'a')).toThrow('Параметр "step" должен быть числом.');
|
38
|
+
});
|
39
|
+
|
40
|
+
test('Должна выбрасывать ошибку, если параметр "step" равен нулю', () => {
|
41
|
+
expect(() => range(1, 5, 0)).toThrow(TypeError);
|
42
|
+
expect(() => range(1, 5, 0)).toThrow('Параметр "step" не может быть равен нулю.');
|
43
|
+
});
|
44
|
+
|
45
|
+
test('Должна выбрасывать ошибку, если параметр "step" отрицательный при start < end', () => {
|
46
|
+
expect(() => range(1, 5, -1)).toThrow(TypeError);
|
47
|
+
expect(() => range(1, 5, -1)).toThrow(
|
48
|
+
'Параметр "step" должен быть больше нуля при start <= end.',
|
49
|
+
);
|
50
|
+
});
|
51
|
+
});
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { shuffle } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция shuffle', () => {
|
5
|
+
test('Должна перемешивать элементы обычного массива', () => {
|
6
|
+
const array = [1, 2, 3, 4, 5];
|
7
|
+
const result = shuffle(array);
|
8
|
+
expect(result).toHaveLength(array.length);
|
9
|
+
expect(result).toEqual(expect.arrayContaining(array));
|
10
|
+
expect(result).not.toEqual(array); // Маловероятно, что массив останется в том же порядке
|
11
|
+
});
|
12
|
+
|
13
|
+
test('Должна перемешивать элементы ассоциативного массива', () => {
|
14
|
+
const array = { a: 1, b: 2, c: 3 };
|
15
|
+
const result = shuffle(array);
|
16
|
+
expect(result).toHaveLength(Object.keys(array).length);
|
17
|
+
expect(result).toEqual(
|
18
|
+
expect.arrayContaining([
|
19
|
+
['a', 1],
|
20
|
+
['b', 2],
|
21
|
+
['c', 3],
|
22
|
+
]),
|
23
|
+
);
|
24
|
+
});
|
25
|
+
|
26
|
+
test('Должна выбрасывать ошибку, если параметр не является массивом', () => {
|
27
|
+
expect(() => shuffle('not an array')).toThrow(TypeError);
|
28
|
+
expect(() => shuffle('not an array')).toThrow('Параметр "arr" должен быть массивом.');
|
29
|
+
});
|
30
|
+
|
31
|
+
test('Должна возвращать пустой массив, если исходный массив пуст', () => {
|
32
|
+
const array = [];
|
33
|
+
const result = shuffle(array);
|
34
|
+
expect(result).toEqual([]);
|
35
|
+
});
|
36
|
+
|
37
|
+
test('Должна корректно перемешивать массив с одним элементом', () => {
|
38
|
+
const array = [1];
|
39
|
+
const result = shuffle(array);
|
40
|
+
expect(result).toEqual([1]);
|
41
|
+
});
|
42
|
+
});
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { sort } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция sort', () => {
|
5
|
+
test('Должна сортировать элементы обычного массива по умолчанию', () => {
|
6
|
+
const array = [5, 3, 1, 4, 2];
|
7
|
+
const result = sort(array);
|
8
|
+
expect(result).toEqual([1, 2, 3, 4, 5]);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна сортировать элементы ассоциативного массива по умолчанию', () => {
|
12
|
+
const array = { a: 3, b: 1, c: 2 };
|
13
|
+
const result = sort(array);
|
14
|
+
expect(result).toEqual([
|
15
|
+
['b', 1],
|
16
|
+
['c', 2],
|
17
|
+
['a', 3],
|
18
|
+
]);
|
19
|
+
});
|
20
|
+
|
21
|
+
test('Должна сортировать элементы обычного массива с использованием пользовательской функции сравнения', () => {
|
22
|
+
const array = [5, 3, 1, 4, 2];
|
23
|
+
const result = sort(array, (a, b) => b[1] - a[1]);
|
24
|
+
expect(result).toEqual([5, 4, 3, 2, 1]);
|
25
|
+
});
|
26
|
+
|
27
|
+
test('Должна сортировать элементы ассоциативного массива с использованием пользовательской функции сравнения', () => {
|
28
|
+
const array = { a: 3, b: 1, c: 2 };
|
29
|
+
const result = sort(array, (a, b) => b[1] - a[1]);
|
30
|
+
expect(result).toEqual([
|
31
|
+
['a', 3],
|
32
|
+
['c', 2],
|
33
|
+
['b', 1],
|
34
|
+
]);
|
35
|
+
});
|
36
|
+
|
37
|
+
test('Должна выбрасывать ошибку, если параметр не является массивом', () => {
|
38
|
+
expect(() => sort('not an array')).toThrow(TypeError);
|
39
|
+
expect(() => sort('not an array')).toThrow('Параметр "arr" должен быть массивом.');
|
40
|
+
});
|
41
|
+
|
42
|
+
test('Должна выбрасывать ошибку, если параметр compare_func не является функцией', () => {
|
43
|
+
expect(() => sort([1, 2, 3], 'not a function')).toThrow(TypeError);
|
44
|
+
expect(() => sort([1, 2, 3], 'not a function')).toThrow(
|
45
|
+
'Параметр "compare_func" должен быть функцией.',
|
46
|
+
);
|
47
|
+
});
|
48
|
+
|
49
|
+
test('Должна корректно сортировать пустой массив', () => {
|
50
|
+
const array = [];
|
51
|
+
const result = sort(array);
|
52
|
+
expect(result).toEqual([]);
|
53
|
+
});
|
54
|
+
|
55
|
+
test('Должна корректно сортировать массив с одним элементом', () => {
|
56
|
+
const array = [1];
|
57
|
+
const result = sort(array);
|
58
|
+
expect(result).toEqual([1]);
|
59
|
+
});
|
60
|
+
});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { is_char } from '../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция is_char', () => {
|
5
|
+
test('Должна возвращать true для одиночного символа', () => {
|
6
|
+
expect(is_char('a')).toBe(true);
|
7
|
+
});
|
8
|
+
|
9
|
+
test('Должна возвращать false для строки из нескольких символов', () => {
|
10
|
+
expect(is_char('abc')).toBe(false);
|
11
|
+
});
|
12
|
+
|
13
|
+
test('Должна возвращать false для пустой строки', () => {
|
14
|
+
expect(is_char('')).toBe(false);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна возвращать false для значения, не являющегося строкой', () => {
|
18
|
+
expect(is_char(1)).toBe(false);
|
19
|
+
expect(is_char(null)).toBe(false);
|
20
|
+
expect(is_char(undefined)).toBe(false);
|
21
|
+
expect(is_char({})).toBe(false);
|
22
|
+
expect(is_char([])).toBe(false);
|
23
|
+
});
|
24
|
+
|
25
|
+
test('Должна возвращать true для пробельного символа', () => {
|
26
|
+
expect(is_char(' ')).toBe(true);
|
27
|
+
});
|
28
|
+
|
29
|
+
test('Должна возвращать false для строки с пробелами', () => {
|
30
|
+
expect(is_char(' a ')).toBe(false);
|
31
|
+
});
|
32
|
+
|
33
|
+
test('Должна возвращать false для строки с числовыми значениями', () => {
|
34
|
+
expect(is_char('123')).toBe(false);
|
35
|
+
});
|
36
|
+
|
37
|
+
test('Должна возвращать true для одиночного числового символа', () => {
|
38
|
+
expect(is_char('1')).toBe(true);
|
39
|
+
});
|
40
|
+
});
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { is_digit_char } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция is_digit_char', () => {
|
5
|
+
test('Должна возвращать true для цифрового символа', () => {
|
6
|
+
expect(is_digit_char('0')).toBe(true);
|
7
|
+
expect(is_digit_char('5')).toBe(true);
|
8
|
+
expect(is_digit_char('9')).toBe(true);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна возвращать false для непробельного символа', () => {
|
12
|
+
expect(is_digit_char('a')).toBe(false);
|
13
|
+
expect(is_digit_char(' ')).toBe(false);
|
14
|
+
expect(is_digit_char('!')).toBe(false);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна возвращать false для строки из нескольких символов', () => {
|
18
|
+
expect(is_digit_char('123')).toBe(false);
|
19
|
+
});
|
20
|
+
|
21
|
+
test('Должна возвращать false для пустой строки', () => {
|
22
|
+
expect(is_digit_char('')).toBe(false);
|
23
|
+
});
|
24
|
+
|
25
|
+
test('Должна возвращать false для значения, не являющегося строкой', () => {
|
26
|
+
expect(is_digit_char(1)).toBe(false);
|
27
|
+
expect(is_digit_char(null)).toBe(false);
|
28
|
+
expect(is_digit_char(undefined)).toBe(false);
|
29
|
+
expect(is_digit_char({})).toBe(false);
|
30
|
+
expect(is_digit_char([])).toBe(false);
|
31
|
+
});
|
32
|
+
});
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { is_whitespace_char } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция is_whitespace_char', () => {
|
5
|
+
test('Должна возвращать true для пробельного символа', () => {
|
6
|
+
expect(is_whitespace_char(' ')).toBe(true);
|
7
|
+
expect(is_whitespace_char('\t')).toBe(true);
|
8
|
+
expect(is_whitespace_char('\n')).toBe(true);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна возвращать false для непробельного символа', () => {
|
12
|
+
expect(is_whitespace_char('a')).toBe(false);
|
13
|
+
expect(is_whitespace_char('1')).toBe(false);
|
14
|
+
expect(is_whitespace_char('!')).toBe(false);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна возвращать false для строки из нескольких символов', () => {
|
18
|
+
expect(is_whitespace_char('abc')).toBe(false);
|
19
|
+
});
|
20
|
+
|
21
|
+
test('Должна возвращать false для пустой строки', () => {
|
22
|
+
expect(is_whitespace_char('')).toBe(false);
|
23
|
+
});
|
24
|
+
|
25
|
+
test('Должна возвращать false для значения, не являющегося строкой', () => {
|
26
|
+
expect(is_whitespace_char(1)).toBe(false);
|
27
|
+
expect(is_whitespace_char(null)).toBe(false);
|
28
|
+
expect(is_whitespace_char(undefined)).toBe(false);
|
29
|
+
expect(is_whitespace_char({})).toBe(false);
|
30
|
+
expect(is_whitespace_char([])).toBe(false);
|
31
|
+
});
|
32
|
+
});
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { natcompare } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция natcompare', () => {
|
5
|
+
test('Должна корректно сравнивать строки с числовыми значениями', () => {
|
6
|
+
expect(natcompare('10', '2')).toBeGreaterThan(0);
|
7
|
+
expect(natcompare('2', '10')).toBeLessThan(0);
|
8
|
+
expect(natcompare('10', '10')).toBe(0);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна корректно сравнивать строки с ведущими нулями', () => {
|
12
|
+
expect(natcompare('0010', '10')).toBe(0);
|
13
|
+
expect(natcompare('010', '10')).toBe(0);
|
14
|
+
expect(natcompare('10', '0010')).toBe(0);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна корректно сравнивать строки с пробелами', () => {
|
18
|
+
expect(natcompare(' 10', '10')).toBe(0);
|
19
|
+
expect(natcompare('10', ' 10')).toBe(0);
|
20
|
+
expect(natcompare(' 10', ' 10')).toBe(0);
|
21
|
+
});
|
22
|
+
|
23
|
+
test('Должна корректно сравнивать строки с буквами и числами', () => {
|
24
|
+
expect(natcompare('a10', 'a2')).toBeGreaterThan(0);
|
25
|
+
expect(natcompare('a2', 'a10')).toBeLessThan(0);
|
26
|
+
expect(natcompare('a10', 'a10')).toBe(0);
|
27
|
+
});
|
28
|
+
|
29
|
+
test('Должна корректно сравнивать строки с разными символами', () => {
|
30
|
+
expect(natcompare('10-', '10+')).toBeGreaterThan(0);
|
31
|
+
expect(natcompare('10+', '10-')).toBeLessThan(0);
|
32
|
+
expect(natcompare('10-', '10-')).toBe(0);
|
33
|
+
});
|
34
|
+
|
35
|
+
test('Должна корректно сравнивать строки с одинаковыми числовыми значениями и разными буквами', () => {
|
36
|
+
expect(natcompare('10a', '10b')).toBeLessThan(0);
|
37
|
+
expect(natcompare('10b', '10a')).toBeGreaterThan(0);
|
38
|
+
expect(natcompare('10a', '10a')).toBe(0);
|
39
|
+
});
|
40
|
+
|
41
|
+
test('Должна корректно сравнивать строки с одинаковыми числовыми значениями и разными регистрами', () => {
|
42
|
+
expect(natcompare('10A', '10a')).toBeLessThan(0);
|
43
|
+
expect(natcompare('10a', '10A')).toBeGreaterThan(0);
|
44
|
+
expect(natcompare('10A', '10A')).toBe(0);
|
45
|
+
});
|
46
|
+
|
47
|
+
test('Должна корректно сравнивать строки с одинаковыми числовыми значениями и разными пробелами', () => {
|
48
|
+
expect(natcompare('10 ', '10')).toBe(0);
|
49
|
+
expect(natcompare('10', '10 ')).toBe(0);
|
50
|
+
expect(natcompare('10 ', '10 ')).toBe(0);
|
51
|
+
});
|
52
|
+
|
53
|
+
test('Должна корректно сравнивать строки с одинаковыми буквами и разными числовыми значениями', () => {
|
54
|
+
expect(natcompare('a10', 'a2')).toBeGreaterThan(0);
|
55
|
+
expect(natcompare('a2', 'a10')).toBeLessThan(0);
|
56
|
+
expect(natcompare('a10', 'a10')).toBe(0);
|
57
|
+
});
|
58
|
+
|
59
|
+
test('Должна корректно сравнивать строки с одинаковыми буквами и одинаковыми числовыми значениями', () => {
|
60
|
+
expect(natcompare('a10', 'a10')).toBe(0);
|
61
|
+
expect(natcompare('a10', 'a10')).toBe(0);
|
62
|
+
expect(natcompare('a10', 'a10')).toBe(0);
|
63
|
+
});
|
64
|
+
|
65
|
+
test('Должна корректно сравнивать строки с разными длинами', () => {
|
66
|
+
expect(natcompare('a', 'aa')).toBeLessThan(0);
|
67
|
+
expect(natcompare('aa', 'a')).toBeGreaterThan(0);
|
68
|
+
expect(natcompare('a', 'a')).toBe(0);
|
69
|
+
});
|
70
|
+
|
71
|
+
test('Должна корректно сравнивать строки с одинаковыми длинами и разными символами', () => {
|
72
|
+
expect(natcompare('a1', 'a2')).toBeLessThan(0);
|
73
|
+
expect(natcompare('a2', 'a1')).toBeGreaterThan(0);
|
74
|
+
expect(natcompare('a1', 'a1')).toBe(0);
|
75
|
+
});
|
76
|
+
|
77
|
+
test('Должна корректно сравнивать строки с одинаковыми длинами и одинаковыми символами', () => {
|
78
|
+
expect(natcompare('a1', 'a1')).toBe(0);
|
79
|
+
expect(natcompare('a1', 'a1')).toBe(0);
|
80
|
+
expect(natcompare('a1', 'a1')).toBe(0);
|
81
|
+
});
|
82
|
+
|
83
|
+
test('Должна корректно сравнивать строки с числами и буквами в разных позициях', () => {
|
84
|
+
expect(natcompare('a1b2', 'a1b10')).toBeLessThan(0);
|
85
|
+
expect(natcompare('a1b10', 'a1b2')).toBeGreaterThan(0);
|
86
|
+
expect(natcompare('a1b2', 'a1b2')).toBe(0);
|
87
|
+
});
|
88
|
+
|
89
|
+
test('Должна корректно сравнивать строки с числами и буквами в разных позициях и разными регистрами', () => {
|
90
|
+
expect(natcompare('a1B2', 'a1b10')).toBeLessThan(0);
|
91
|
+
expect(natcompare('a1b10', 'a1B2')).toBeGreaterThan(0);
|
92
|
+
expect(natcompare('a1B2', 'a1B2')).toBe(0);
|
93
|
+
});
|
94
|
+
|
95
|
+
test('Должна корректно сравнивать строки с числами и буквами в разных позициях и разными символами', () => {
|
96
|
+
expect(natcompare('a1-b2', 'a1+b10')).toBeLessThan(0);
|
97
|
+
expect(natcompare('a1+b10', 'a1-b2')).toBeGreaterThan(0);
|
98
|
+
expect(natcompare('a1-b2', 'a1-b2')).toBe(0);
|
99
|
+
});
|
100
|
+
});
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import { expect, test, describe } from '@jest/globals';
|
2
|
+
import { natcompare_numeric } from '../../../index.mjs';
|
3
|
+
|
4
|
+
describe('Функция natcompare_numeric', () => {
|
5
|
+
test('Должна корректно сравнивать строки с числовыми значениями', () => {
|
6
|
+
expect(natcompare_numeric('10', '2')).toBeGreaterThan(0);
|
7
|
+
expect(natcompare_numeric('2', '10')).toBeLessThan(0);
|
8
|
+
expect(natcompare_numeric('10', '10')).toBe(0);
|
9
|
+
});
|
10
|
+
|
11
|
+
test('Должна корректно сравнивать строки с ведущими нулями', () => {
|
12
|
+
expect(natcompare_numeric('0010', '10')).toBe(0);
|
13
|
+
expect(natcompare_numeric('010', '10')).toBe(0);
|
14
|
+
expect(natcompare_numeric('10', '0010')).toBe(0);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('Должна корректно сравнивать строки с пробелами', () => {
|
18
|
+
expect(natcompare_numeric(' 10', '10')).toBe(0);
|
19
|
+
expect(natcompare_numeric('10', ' 10')).toBe(0);
|
20
|
+
expect(natcompare_numeric(' 10', ' 10')).toBe(0);
|
21
|
+
});
|
22
|
+
|
23
|
+
test('Должна корректно сравнивать строки с буквами и числами', () => {
|
24
|
+
expect(natcompare_numeric('a10', 'a2')).toBeGreaterThan(0);
|
25
|
+
expect(natcompare_numeric('a2', 'a10')).toBeLessThan(0);
|
26
|
+
expect(natcompare_numeric('a10', 'a10')).toBe(0);
|
27
|
+
});
|
28
|
+
|
29
|
+
test('Должна корректно сравнивать строки с разными символами', () => {
|
30
|
+
expect(natcompare_numeric('10-', '10+')).toBe(0);
|
31
|
+
expect(natcompare_numeric('10+', '10-')).toBe(0);
|
32
|
+
expect(natcompare_numeric('10-', '10-')).toBe(0);
|
33
|
+
});
|
34
|
+
|
35
|
+
test('Должна выбрасывать ошибку, если параметр "a" не является строкой', () => {
|
36
|
+
expect(() => natcompare_numeric(10, '2')).toThrow(TypeError);
|
37
|
+
expect(() => natcompare_numeric(10, '2')).toThrow('Параметр "a" должен быть строкой.');
|
38
|
+
});
|
39
|
+
|
40
|
+
test('Должна выбрасывать ошибку, если параметр "b" не является строкой', () => {
|
41
|
+
expect(() => natcompare_numeric('10', 2)).toThrow(TypeError);
|
42
|
+
expect(() => natcompare_numeric('10', 2)).toThrow('Параметр "b" должен быть строкой.');
|
43
|
+
});
|
44
|
+
|
45
|
+
test('Должна корректно сравнивать строки с одинаковыми числовыми значениями и разными буквами', () => {
|
46
|
+
expect(natcompare_numeric('10a', '10b')).toBe(0);
|
47
|
+
expect(natcompare_numeric('10b', '10a')).toBe(0);
|
48
|
+
expect(natcompare_numeric('10a', '10a')).toBe(0);
|
49
|
+
});
|
50
|
+
|
51
|
+
test('Должна корректно сравнивать строки с одинаковыми числовыми значениями и разными регистрами', () => {
|
52
|
+
expect(natcompare_numeric('10A', '10a')).toBe(0);
|
53
|
+
expect(natcompare_numeric('10a', '10A')).toBe(0);
|
54
|
+
expect(natcompare_numeric('10A', '10A')).toBe(0);
|
55
|
+
});
|
56
|
+
|
57
|
+
test('Должна корректно сравнивать строки с одинаковыми числовыми значениями и разными пробелами', () => {
|
58
|
+
expect(natcompare_numeric('10 ', '10')).toBe(0);
|
59
|
+
expect(natcompare_numeric('10', '10 ')).toBe(0);
|
60
|
+
expect(natcompare_numeric('10 ', '10 ')).toBe(0);
|
61
|
+
});
|
62
|
+
|
63
|
+
test('Должна корректно сравнивать строки с одинаковыми буквами и разными числовыми значениями', () => {
|
64
|
+
expect(natcompare_numeric('a10', 'a2')).toBeGreaterThan(0);
|
65
|
+
expect(natcompare_numeric('a2', 'a10')).toBeLessThan(0);
|
66
|
+
expect(natcompare_numeric('a10', 'a10')).toBe(0);
|
67
|
+
});
|
68
|
+
|
69
|
+
test('Должна корректно сравнивать строки с одинаковыми буквами и одинаковыми числовыми значениями', () => {
|
70
|
+
expect(natcompare_numeric('a10', 'a10')).toBe(0);
|
71
|
+
expect(natcompare_numeric('a10', 'a10')).toBe(0);
|
72
|
+
expect(natcompare_numeric('a10', 'a10')).toBe(0);
|
73
|
+
});
|
74
|
+
|
75
|
+
test('Должна корректно сравнивать строки с разными длинами', () => {
|
76
|
+
expect(natcompare_numeric('a', 'aa')).toBeLessThan(0);
|
77
|
+
expect(natcompare_numeric('aa', 'a')).toBeGreaterThan(0);
|
78
|
+
expect(natcompare_numeric('a', 'a')).toBe(0);
|
79
|
+
});
|
80
|
+
|
81
|
+
test('Должна корректно сравнивать строки с одинаковыми длинами и разными символами', () => {
|
82
|
+
expect(natcompare_numeric('a1', 'a2')).toBeLessThan(0);
|
83
|
+
expect(natcompare_numeric('a2', 'a1')).toBeGreaterThan(0);
|
84
|
+
expect(natcompare_numeric('a1', 'a1')).toBe(0);
|
85
|
+
});
|
86
|
+
|
87
|
+
test('Должна корректно сравнивать строки с одинаковыми длинами и одинаковыми символами', () => {
|
88
|
+
expect(natcompare_numeric('a1', 'a1')).toBe(0);
|
89
|
+
expect(natcompare_numeric('a1', 'a1')).toBe(0);
|
90
|
+
expect(natcompare_numeric('a1', 'a1')).toBe(0);
|
91
|
+
});
|
92
|
+
|
93
|
+
test('Должна корректно сравнивать строки с числами и буквами в разных позициях', () => {
|
94
|
+
expect(natcompare_numeric('a1b2', 'a1b10')).toBeLessThan(0);
|
95
|
+
expect(natcompare_numeric('a1b10', 'a1b2')).toBeGreaterThan(0);
|
96
|
+
expect(natcompare_numeric('a1b2', 'a1b2')).toBe(0);
|
97
|
+
});
|
98
|
+
|
99
|
+
test('Должна корректно сравнивать строки с числами и буквами в разных позициях и разными регистрами', () => {
|
100
|
+
expect(natcompare_numeric('a1B2', 'a1b10')).toBeLessThan(0);
|
101
|
+
expect(natcompare_numeric('a1b10', 'a1B2')).toBeGreaterThan(0);
|
102
|
+
expect(natcompare_numeric('a1B2', 'a1B2')).toBe(0);
|
103
|
+
});
|
104
|
+
|
105
|
+
test('Должна корректно сравнивать строки с числами и буквами в разных позициях и разными символами', () => {
|
106
|
+
expect(natcompare_numeric('a1-b2', 'a1+b10')).toBeLessThan(0);
|
107
|
+
expect(natcompare_numeric('a1+b10', 'a1-b2')).toBeGreaterThan(0);
|
108
|
+
expect(natcompare_numeric('a1-b2', 'a1-b2')).toBe(0);
|
109
|
+
});
|
110
|
+
});
|