-
Notifications
You must be signed in to change notification settings - Fork 35
/
analyzer.spec.js
151 lines (119 loc) · 5.38 KB
/
analyzer.spec.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// We import the object 'analyzer' which contains the functions.
import analyzer from '../src/analyzer';
const TEST_TEXT_NO_NUMBERS = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
const TEST_TEXT_NUMBERS = 'If I have 8 apples and I buy 2 more, how many apples do I have in total?';
const TEST_TEXT_DECIMALS = 'Calculate the sum of 1.65 plus 0.15 plus 1.10.';
const TEST_TEXT_NOT_A_NUMBER = 'This is not a number: 41u0003jot';
describe('analyzer', () => {
describe('analyzer.getWordCount', () => {
it('should return 19 for "' + TEST_TEXT_NO_NUMBERS + '"', () => {
expect(analyzer.getWordCount(TEST_TEXT_NO_NUMBERS)).toBe(19);
});
});
describe('analyzer.getCharacterCount', () => {
it('should return 123 for "' + TEST_TEXT_NO_NUMBERS + '"', () => {
expect(analyzer.getCharacterCount(TEST_TEXT_NO_NUMBERS)).toBe(123);
});
});
describe('analyzer.getCharacterCountExcludingSpaces', () => {
it('should return 102 for "' + TEST_TEXT_NO_NUMBERS + '"', () => {
expect(analyzer.getCharacterCountExcludingSpaces(TEST_TEXT_NO_NUMBERS)).toBe(102);
});
});
describe('analyzer.getAverageWordLength', () => {
it('should return 5.53 for "' + TEST_TEXT_NO_NUMBERS + '"', () => {
expect(analyzer.getAverageWordLength(TEST_TEXT_NO_NUMBERS)).toBe(5.53);
});
});
describe('analyzer.getNumberCount', () => {
it('should return 0 for "' + TEST_TEXT_NOT_A_NUMBER + '"', () => {
expect(analyzer.getNumberCount(TEST_TEXT_NOT_A_NUMBER)).toBe(0);
});
it('should return 3 for "' + TEST_TEXT_DECIMALS + '"', () => {
expect(analyzer.getNumberCount(TEST_TEXT_DECIMALS)).toBe(3);
});
it('should return 2 for "' + TEST_TEXT_NUMBERS + '"', () => {
expect(analyzer.getNumberCount(TEST_TEXT_NUMBERS)).toBe(2);
});
});
describe('analyzer.getNumberSum', () => {
it('should return 0 for "' + TEST_TEXT_NO_NUMBERS + '"', () => {
expect(analyzer.getNumberSum(TEST_TEXT_NO_NUMBERS)).toBe(0);
});
it('should return 0 for "' + TEST_TEXT_NOT_A_NUMBER + '"', () => {
expect(analyzer.getNumberSum(TEST_TEXT_NOT_A_NUMBER)).toBe(0);
});
it('should return 2.9 for "' + TEST_TEXT_DECIMALS + '"', () => {
expect(analyzer.getNumberSum(TEST_TEXT_DECIMALS)).toBe(2.9);
});
it('should return 10 for "' + TEST_TEXT_NUMBERS + '"', () => {
expect(analyzer.getNumberSum(TEST_TEXT_NUMBERS)).toBe(10);
});
});
});
//TODO: Remove .skip to execute the test for optional functionalities.
describe.skip('Optional:', () => {
const TEST_TEST_EMPTY = '';
const TEST_TEST_SPACES = ' ';
const TEST_TEXT_PUNCTUATION_MARKS = '.,;:"«»[]{}()¿?¡!-';
describe('analyzer.getWordCount', () => {
it('should return 0 for "' + TEST_TEST_EMPTY + '"', () => {
expect(analyzer.getWordCount(TEST_TEST_EMPTY)).toBe(0);
});
it('should return 0 for "' + TEST_TEST_SPACES + '"', () => {
expect(analyzer.getWordCount(TEST_TEST_SPACES)).toBe(0);
});
it('should return 0 for "' + TEST_TEXT_PUNCTUATION_MARKS + '"', () => {
expect(analyzer.getWordCount(TEST_TEXT_PUNCTUATION_MARKS)).toBe(0);
});
});
describe('analyzer.getCharacterCount', () => {
it('should return 0 for "' + TEST_TEST_EMPTY + '"', () => {
expect(analyzer.getCharacterCount(TEST_TEST_EMPTY)).toBe(0);
});
it('should return 7 for "' + TEST_TEST_SPACES + '"', () => {
expect(analyzer.getCharacterCount(TEST_TEST_SPACES)).toBe(7);
});
it('should return 18 for "' + TEST_TEXT_PUNCTUATION_MARKS + '"', () => {
expect(analyzer.getCharacterCount(TEST_TEXT_PUNCTUATION_MARKS)).toBe(18);
});
});
describe('analyzer.getCharacterCountExcludingSpaces', () => {
it('should return 0 for "' + TEST_TEST_EMPTY + '"', () => {
expect(analyzer.getCharacterCountExcludingSpaces(TEST_TEST_EMPTY)).toBe(0);
});
it('should return 0 for "' + TEST_TEST_SPACES + '"', () => {
expect(analyzer.getCharacterCountExcludingSpaces(TEST_TEST_SPACES)).toBe(0);
});
it('should return 0 for "' + TEST_TEXT_PUNCTUATION_MARKS + '"', () => {
expect(analyzer.getCharacterCountExcludingSpaces(TEST_TEXT_PUNCTUATION_MARKS)).toBe(0);
});
});
describe('analyzer.getAverageWordLength', () => {
it('should return 0 for "' + TEST_TEST_EMPTY + '"', () => {
expect(analyzer.getAverageWordLength(TEST_TEST_EMPTY)).toBe(0);
});
it('should return 0 for "' + TEST_TEST_SPACES + '"', () => {
expect(analyzer.getAverageWordLength(TEST_TEST_SPACES)).toBe(0);
});
it('should return 0 for "' + TEST_TEXT_PUNCTUATION_MARKS + '"', () => {
expect(analyzer.getAverageWordLength(TEST_TEXT_PUNCTUATION_MARKS)).toBe(0);
});
});
describe('analyzer.getNumberCount', () => {
it('should return 0 for "' + TEST_TEST_EMPTY + '"', () => {
expect(analyzer.getNumberCount(TEST_TEST_EMPTY)).toBe(0);
});
it('should return 0 for "' + TEST_TEST_SPACES + '"', () => {
expect(analyzer.getNumberCount(TEST_TEST_SPACES)).toBe(0);
});
});
describe('analyzer.getNumberSum', () => {
it('should return 0 for "' + TEST_TEST_EMPTY + '"', () => {
expect(analyzer.getNumberSum(TEST_TEST_EMPTY)).toBe(0);
});
it('should return 0 for "' + TEST_TEST_SPACES + '"', () => {
expect(analyzer.getNumberSum(TEST_TEST_SPACES)).toBe(0);
});
});
});