-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.test.js
133 lines (116 loc) · 4.25 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { expect, test, describe } from 'vitest';
import { coerceToArray, appendEach, prependEach } from './index.js';
import permuteArrays from './index.js';
describe('coerceToArray', () => {
test('should return the input array if it is already an array', () => {
const input = [1, 2, 3];
const result = coerceToArray(input);
expect(result).toEqual(input);
});
test('should convert a string to an array with the string as the only element', () => {
const input = 'hello';
const result = coerceToArray(input);
expect(result).toEqual(['hello']);
});
test('should return undefined for any other input type', () => {
const input = { key: 'value' };
const result = coerceToArray(input);
expect(result).toBe(undefined);
});
});
describe('appendEach', () => {
test('should append each suffix to each term in the array', () => {
const term = ['fast', 'slow'];
const suffixes = ['er', 'est'];
const result = appendEach(term, suffixes);
expect(result).toEqual(['faster', 'fastest', 'slower', 'slowest']);
});
test('should return an empty array if the term is an empty array', () => {
const term = [];
const suffixes = ['s', 'es'];
const result = appendEach(term, suffixes);
expect(result).toEqual([]);
});
test('should return an empty array if the suffixes array is empty', () => {
const term = ['apple', 'banana'];
const suffixes = [];
const result = appendEach(term, suffixes);
expect(result).toEqual([]);
});
test('should return an empty array if both the term and suffixes arrays are empty', () => {
const term = [];
const suffixes = [];
const result = appendEach(term, suffixes);
expect(result).toEqual([]);
});
});
describe('prependEach', () => {
test('should prepend each prefix to each term in the array', () => {
const term = ['fast', 'slow'];
const prefixes = ['super', 'ultra'];
const result = prependEach(term, prefixes);
expect(result).toEqual(['superfast', 'ultrafast', 'superslow', 'ultraslow']);
});
test('should return an empty array if the term is an empty array', () => {
const term = [];
const prefixes = ['big', 'small'];
const result = prependEach(term, prefixes);
expect(result).toEqual([]);
});
test('should return an empty array if the prefixes array is empty', () => {
const term = ['apple', 'banana'];
const prefixes = [];
const result = prependEach(term, prefixes);
expect(result).toEqual([]);
});
test('should return an empty array if both the term and prefixes arrays are empty', () => {
const term = [];
const prefixes = [];
const result = prependEach(term, prefixes);
expect(result).toEqual([]);
});
});
describe('permuteArrays', () => {
test('should prepend each prefix and append each suffix to each term in the array', () => {
const term = ['a'];
const prefixes = ['d', 'r'];
const suffixes = ['d', 'm'];
const result = permuteArrays(term, prefixes, suffixes);
expect(result).toEqual(['da', 'ra', 'ad', 'am', 'dad', 'dam', 'rad', 'ram']);
});
test('should return an empty array if the term is an empty array', () => {
const term = [];
const prefixes = ['big', 'small'];
const suffixes = ['s', 'es'];
const result = permuteArrays(term, prefixes, suffixes);
expect(result).toEqual([]);
});
test('should return term with suffixes if the prefixes array is empty', () => {
const term = ['high', 'low'];
const prefixes = [];
const suffixes = ['ly', 'est'];
const result = permuteArrays(term, prefixes, suffixes);
expect(result).toEqual(['highly', 'highest', 'lowly', 'lowest']);
});
test('should return an empty array if the suffixes array is empty', () => {
const term = ['way', 'line'];
const prefixes = ['high', 'by'];
const suffixes = [];
const result = permuteArrays(term, prefixes, suffixes);
expect(result).toEqual(['highway', 'byway', 'highline', 'byline']);
});
test('should return an empty array if both arrays are empty', () => {
const term = [];
const prefixes = [];
const suffixes = [];
const result = permuteArrays(term, prefixes, suffixes);
expect(result).toEqual([]);
});
test('Default empty prefix and suffix values work as expected', () => {
const term = ['fee', 'fi'];
const prefixes = undefined;
const suffixes = undefined;
const result = permuteArrays(term, prefixes, suffixes);
expect(result).toEqual([]);
});
});