-
Notifications
You must be signed in to change notification settings - Fork 321
Expand file tree
/
Copy pathch1-q4.spec.js
More file actions
71 lines (54 loc) · 1.65 KB
/
ch1-q4.spec.js
File metadata and controls
71 lines (54 loc) · 1.65 KB
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
import { expect } from 'chai';
import * as funcs from './ch1-q4';
for (let key in funcs) {
let func = funcs[key];
describe('ch1-q4: ' + key, function() {
it('returns false with null/undefined as input', function() {
expect(func(undefined)).to.be.false;
expect(func(null)).to.be.false;
});
it('returns true for an empty array', function() {
expect(func([])).to.be.true;
});
[
' ',
' ',
'Tact Coa',
'aabb',
'ab a b',
' a b a b ',
'sasadfgsadfghjk;hjk;sadfghjk;dfghjk;',
'sa sadfgsadfgh jk;hjkz;sadfg hjk;dfghjk;'
].forEach(arg => {
if (key === 'isPalindromePermutationsBit') {
if(/^[a-zA-Z\s]+$/.test(arg)) {
it(`returns true for palindromic string which only contains English alphabet and space: '${arg}'`, function() {
expect(func(arg.split(''))).to.be.true;
});
}
} else {
it(`returns true for palindromic string: '${arg}'`, function() {
expect(func(arg.split(''))).to.be.true;
});
}
});
[
'abcadef',
'1234567890',
'a b',
'sg! sG$'
].forEach(arg => {
if (key === 'isPalindromePermutationsBit') {
if(/^[a-zA-Z\s]+$/.test(arg)) {
it(`returns false for palindromic string which only contains English alphabet and space: '${arg}'`, function() {
expect(func(arg.split(''))).to.be.false;
});
}
} else {
it(`returns false for non-palindromic string: '${arg}'`, function() {
expect(func(arg.split(''))).to.be.false;
});
}
});
});
}