-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
48 lines (43 loc) · 1.67 KB
/
tests.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
import {isString, notString} from './index.js';
var strings = ['', ' ', ' ', '\n', '\r', '\\', '\'', '"', '`', '1', '0', '!@#$%^&*()'];
var nonStrings = [true, 1, 0.0001, [8, 9], {}, function (i) { return (i === 2); }, false, { prop: 1 }, ['hello']];
// Test 1: This must return true each time to pass:
var results = [];
for (var i = 0; i < strings.length; ++i) {
results.push(isString(strings[i]));
}
if (results.length === strings.length && !(results.includes(undefined))
&& !(results.includes(false)) && results.includes(true))
console.log('test 1 passed');
else
console.log('test 1 FAILED');
// Test 2: This must return false each time to pass:
results = [];
for (var i = 0; i < nonStrings.length; ++i) {
results.push(isString(nonStrings[i]));
}
if (results.length === nonStrings.length && !(results.includes(undefined))
&& !(results.includes(true)) && results.includes(false))
console.log('test 2 passed');
else
console.log('test 2 FAILED');
// Test 3: This must return true each time to pass:
results = [];
for (var i = 0; i < nonStrings.length; ++i) {
results.push(notString(nonStrings[i]));
}
if (results.length === nonStrings.length && !(results.includes(undefined))
&& !(results.includes(false)) && results.includes(true))
console.log('test 3 passed');
else
console.log('test 3 FAILED');
// Test 4: This must return false each time to pass:
results = [];
for (var i = 0; i < strings.length; ++i) {
results.push(notString(strings[i]));
}
if (results.length === strings.length && !(results.includes(undefined))
&& !(results.includes(true)) && results.includes(false))
console.log('test 4 passed');
else
console.log('test 4 FAILED');