-
Notifications
You must be signed in to change notification settings - Fork 0
/
diamond.test.js
70 lines (53 loc) · 1.82 KB
/
diamond.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
const diamond = require('./diamond');
describe('test "C" diamond', () => {
const testChar = 'C';
const lineForChar = diamond.lineForDiamond(testChar);
test('line for A', () => {
expect(lineForChar('A')).toBe(' A');
});
test('line for B', () => {
expect(lineForChar('B')).toBe(' B B');
});
test('line for C', () => {
expect(lineForChar('C')).toBe('C C');
});
test('diamond height is 5', () => {
expect(diamond.buildDiamond(testChar).length).toBe(5);
});
});
describe('test various diamonds', () => {
test('test "a" diamond', () => {
expect(diamond.buildDiamond('a').length).toBe(65);
});
test('test boundary of diamond', () => {
expect(diamond.buildDiamond('z').length).toBe(115);
expect(diamond.buildDiamond('{').length).toBe(0);
});
test('test multi-letter string takes first', () => {
expect(diamond.buildDiamond('CBA').length).toBe(5);
});
test('test integer diamond returns empty', () => {
expect(diamond.buildDiamond(122).length).toBe(0);
});
test('test unicode character diamond returns empty', () => {
expect(diamond.buildDiamond('\u{20BB7}').length).toBe(0);
});
test('test special character returns empty', () => {
expect(diamond.buildDiamond('$').length).toBe(0);
});
test('test number as string returns empty', () => {
expect(diamond.buildDiamond('1234').length).toBe(0);
});
test('test empty string returns empty', () => {
expect(diamond.buildDiamond('').length).toBe(0);
});
test('test whitespace string returns empty', () => {
expect(diamond.buildDiamond(' ').length).toBe(0);
});
test('test object returns empty', () => {
expect(diamond.buildDiamond({hi: 'there'}).length).toBe(0);
});
test('test list returns empty', () => {
expect(diamond.buildDiamond(['hi', 'there']).length).toBe(0);
});
});