forked from GSA-TTS/usdc-find-search-term-in-books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook_search.js
669 lines (555 loc) · 24.7 KB
/
book_search.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
/**
* RECOMMENDATION
*
* To test your code, you should open "tester.html" in a web browser.
* You can then use the "Developer Tools" to see the JavaScript console.
* There, you will see the results unit test execution. You are welcome
* to run the code any way you like, but this is similar to how we will
* run your code submission.
*
* The Developer Tools in Chrome are available under the "..." menu,
* futher hidden under the option "More Tools." In Firefox, they are
* under the hamburger (three horizontal lines), also hidden under "More Tools."
*/
/**
* @typedef {JSON} Line
* @property {number} Page - Number of the page with this line in a book
* @property {number} Line - Number of this line on the page with this line
* @property {string} Text - Text of this line
*/
/**
* @typedef {JSON} ExcerptOfBook
* @property {string} Title - Title of the book of this excerpt
* @property {string} ISBN - ISBN of the book of this excerpt
* @property {Line[]} Content - Array of lines in the book of this excerpt
*/
/**
* @typedef {JSON} SearchResult
* @property {string} ISBN - ISBN of a book
* @property {number} Page - Number of the page with the line indicated by
* number Line
* @property {number} Line - Number of a line with text containing the word
* searchTerm or the beginning of the word searchTerm. If a word is split by a
* hyphen across two lines, a search result for the former line will be
* provided.
*/
/**
* @typedef {JSON} Result
* @property {string} SearchTerm - word searchTerm
* @property {SearchResult[]} - array of search results arrayOfSearchResults
*/
/**
* Adds a created search result to an array of search results
* @param {string} isbn - An ISBN
* @param {number} page - A number of a page
* @param {number} line - A number of a line
* @param {SearchResult[]} arrayOfSearchResults
* @returns {undefined}
*/
function addSearchResultToArrayOfSearchResults(isbn, page, line, arrayOfSearchResults) {
/** @type {SearchResult} */
const searchResult = {
"ISBN": isbn,
"Page": page,
"Line": line
}
arrayOfSearchResults.push(searchResult);
}
/**
* Creates search term with optional syllables after the first syllable
* @param {string} searchTerm - search term
* @returns searchTermWithOptionalSyllabicPhrases - search term with optional syllables
*/
function createSearchTermWithOptionalSyllabicPhrases(searchTerm) {
let searchTermWithOptionalSyllabicPhrases = "";
let numberOfOpenParentheses = 0;
let k;
for (k = 0; k < searchTerm.length - 1; k++) {
if (searchTerm[k] === '-' && searchTerm[k + 1] !== '?') {
searchTermWithOptionalSyllabicPhrases = searchTermWithOptionalSyllabicPhrases + "-(";
numberOfOpenParentheses++;
} else if (searchTerm[k] === '-' && searchTerm[k + 1] === '?') {
searchTermWithOptionalSyllabicPhrases = searchTermWithOptionalSyllabicPhrases + "-?(";
k = k + 1;
numberOfOpenParentheses++;
} else {
searchTermWithOptionalSyllabicPhrases = searchTermWithOptionalSyllabicPhrases + searchTerm[k];
}
}
searchTermWithOptionalSyllabicPhrases = searchTermWithOptionalSyllabicPhrases + searchTerm[k];
for (let l = 0; l < numberOfOpenParentheses; l++) {
searchTermWithOptionalSyllabicPhrases = searchTermWithOptionalSyllabicPhrases + ")?";
}
return searchTermWithOptionalSyllabicPhrases;
}
/**
* Searches for matches in scanned text.
* @param {string} searchTerm - The word or term we're searching for. A word
* contains one or more letters and contains either an optional / soft hyphen
* or a required hyphen after each syllable. A word may contain one or more
* non-adjacent apostrophes.
* @param {ExcerptOfBook[]} scannedTextObj - An array of excerpts of books
* @returns {Result} - A result containing search term searchTerm an an array
* of search results
*/
function findSearchTermInBooks(searchTerm, scannedTextObj) {
/** @type {SearchResult[]} */
const arrayOfSearchResults = [];
/** @type {RegExp} */
const regularExpressionDerivedFromSearchTerm = new RegExp(searchTerm);
/** @type {number} */
const numberOfExcerptsOfBooks = scannedTextObj.length;
for (let i = 0; i < numberOfExcerptsOfBooks; i++) {
/** @type {ExcerptOfBook} */
const excerptOfBook = scannedTextObj[i];
/** @type {number} */
const isbn = excerptOfBook.ISBN;
/** @type {Line[]} */
let arrayOfLines = null;
/** @type {number} */
let numberOfLines = 0;
if (excerptOfBook.hasOwnProperty('Content')) {
arrayOfLines = excerptOfBook.Content;
numberOfLines = arrayOfLines.length;
}
for (let j = 0; j < numberOfLines; j++) {
/** @type {Line} */
const lineJ = arrayOfLines[j];
/** @type {string} */
const textOfLineJ = lineJ.Text;
if (regularExpressionDerivedFromSearchTerm.test(textOfLineJ)) {
addSearchResultToArrayOfSearchResults(isbn, lineJ.Page, lineJ.Line, arrayOfSearchResults)
} else if (textOfLineJ.endsWith('-')) {
/** @type {string[]} */
const arrayOfTokensOfLineJ = textOfLineJ.split(/[^a-zA-Z'-]+/);
/** @type {number} */
const numberOfTokensOfLineJ = arrayOfTokensOfLineJ.length;
/** @type {string} */
const lastTokenOfLineJ = arrayOfTokensOfLineJ[numberOfTokensOfLineJ - 1];
if (j === numberOfLines - 1) {
/** @type {string} */
const searchTermWithOptionalSyllabicPhrases = createSearchTermWithOptionalSyllabicPhrases(searchTerm);
/** @type {RegExp} */
const regularExpressionDerivedFromSearchTermWithOptionalSyllabicPhrases = new RegExp(searchTermWithOptionalSyllabicPhrases);
if (regularExpressionDerivedFromSearchTermWithOptionalSyllabicPhrases.test(lastTokenOfLineJ)) {
addSearchResultToArrayOfSearchResults(isbn, lineJ.Page, lineJ.Line, arrayOfSearchResults)
console.log('WARNING: A search result has been added to an array of search results for a search term that begins with the last token of an excerpt.');
}
} else {
/** @type {Line} */
const lineJPlus1 = arrayOfLines[j + 1];
/** @type {string} */
const textOfLineJPlus1 = lineJPlus1.Text;
/** @type {string[]} */
const arrayOfTokensOfLineJPlus1 = textOfLineJPlus1.split(/[^a-zA-Z'-]+/);
/** @type {string} */
const firstTokenOfLineJPlus1 = arrayOfTokensOfLineJPlus1[0];
/** @type {string} */
const lastTokenOfLineJPlusFirstTokenOfLineJPlus1 = lastTokenOfLineJ + firstTokenOfLineJPlus1;
if (regularExpressionDerivedFromSearchTerm.test(lastTokenOfLineJPlusFirstTokenOfLineJPlus1)) {
addSearchResultToArrayOfSearchResults(isbn, lineJ.Page, lineJ.Line, arrayOfSearchResults)
}
}
}
}
}
/**
* @type {Result}
*/
const result = {
"SearchTerm": searchTerm,
"Results": arrayOfSearchResults
};
return result;
}
/** Input object for tests 1, 2, 3, 5, 8, and 11 */
/** @type {ExcerptOfBook[]} */
const twentyLeaguesIn = [
{
"Title": "Twenty Thousand Leagues Under the Sea",
"ISBN": "9780000528531",
"Content": [
{
"Page": 31,
"Line": 8,
"Text": "now simply went on by her own momentum. The dark-"
},
{
"Page": 31,
"Line": 9,
"Text": "ness was then profound; and however good the Canadian\'s"
},
{
"Page": 31,
"Line": 10,
"Text": "eyes were, I asked myself how he had managed to see, and"
}
]
}
];
/** Input object for tests 4 and 6 */
/** @type {ExcerptOfBook[]} */
const arrayWithExcerptFromTwentyThousandLeaguesUnderTheSeaWithOneLine = [
{
"Title": "Twenty Thousand Leagues Under the Sea",
"ISBN": "9780000528531",
"Content": [
{
"Page": 31,
"Line": 8,
"Text": "now simply went on by her own momentum. The dark-"
}
]
}
];
/** Input object for test 7 */
/** @type {ExcerptOfBook[]} */
const arrayOfExcerptsFromBooksWithWordDarkHaired = [
{
"Title": "Book With Excerpt With First Line Ending With dark- and Second Line Beginning With haired",
"ISBN": "0123456789123",
"Content": [
{
"Page": 0,
"Line": 1,
"Text": "now simply went on by her own momentum. The dark-"
},
{
"Page": 0,
"Line": 2,
"Text": "haired woman was beautiful; and however good the Canadian\'s"
}
]
}
];
/** Input object for test 9 */
/** @type {ExcerptOfBook[]} */
const arrayOfZeroExcerptsFromBooks = []
/** Input object for test 10 */
/** @type {ExcerptOfBook[]} */
const arrayOfExcerptFromBookWithNoContent = [
{
"Title": "Book With No Content",
"ISBN": "0123456789123"
}
]
/** Input object for test 13 */
/** @type {ExcerptOfBook[]} */
const arrayOfExcerptFromBookWithMoOnLastLine = [
{
"Title": "Book With Excerpt With Mo- On Last Line",
"ISBN": "0123456789123",
"Content": [
{
"Page": 0,
"Line": 1,
"Text": "The mother of a person's spouse is that person's mo-"
}
]
}
];
/** Input object for test 14 */
/** @type {ExcerptOfBook[]} */
const arrayOfExcerptFromBookWithMotherOnLastLine = [
{
"Title": "Book With Excerpt With Mother- On Last Line",
"ISBN": "0123456789123",
"Content": [
{
"Page": 0,
"Line": 1,
"Text": "The mother of a person's spouse is that person's mother-"
}
]
}
];
/** Input object for test 15 */
/** @type {ExcerptOfBook[]} */
const arrayOfExcerptFromBookWithMotherInOnLastLine = [
{
"Title": "Book With Excerpt With Mother-In- On Last Line",
"ISBN": "0123456789123",
"Content": [
{
"Page": 0,
"Line": 1,
"Text": "The mother of a person's spouse is that person's mother-in-"
}
]
}
];
/** Output object for tests 1 and 2 */
/** @type {Result} */
const twentyLeaguesOut = {
"SearchTerm": "the",
"Results": [
{
"ISBN": "9780000528531",
"Page": 31,
"Line": 9
}
]
};
/** Output object for test 3 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermDarknessAndArrayTwentyLeaguesIn = {
"SearchTerm": "dark-?ness",
"Results": [
{
"ISBN": "9780000528531",
"Page": 31,
"Line": 8
}
]
};
/** Output object for test 4 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermDarknessAndArrayWithExcerptFromTwentyThousandLeaguesUnderTheSeaWithOneLine = {
"SearchTerm": "dark-?ness",
"Results": [
{
"ISBN": "9780000528531",
"Page": 31,
"Line": 8
}
]
};
/** Output object for test 5 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermDarkHairedAndArrayTwentyLeaguesIn = {
"SearchTerm": "dark-haired",
"Results": []
};
/** Output object for test 6 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermDarkHairedAndArrayWithExcerptFromTwentyThousandLeaguesUnderTheSeaWithOneLine = {
"SearchTerm": "dark-haired",
"Results": [
{
"ISBN": "9780000528531",
"Page": 31,
"Line": 8
}
]
};
/** Output object for test 7 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermDarkHairedAndArrayOfExcerptsFromBooksWithWordDarkHaired = {
"SearchTerm": "dark-haired",
"Results": [
{
"ISBN": "0123456789123",
"Page": 0,
"Line": 1
}
]
};
/** Output object for test 8 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermCanadiansAndTwentyLeaguesIn = {
"SearchTerm": "Ca-?na-?di-?an's",
"Results": [
{
"ISBN": "9780000528531",
"Page": 31,
"Line": 9
}
]
};
/** Output object for test 9 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermTheAndArrayOfZeroExcerptsFromBooks = {
"SearchTerm": "the",
"Results": []
}
/** Output object for test 10 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermTheAndArrayOfExcerptOfBookWithNoContent = {
"SearchTerm": "the",
"Results": []
}
/** Output object for test 11 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermTheAndArrayTwentyLeaguesIn = {
"SearchTerm": "The",
"Results": [
{
"ISBN": "9780000528531",
"Page": 31,
"Line": 8
}
]
};
/** Output object for tests 13, 14, and 15 */
/** @type {Result} */
const outputOfFindSearchTermInBooksForSearchTermMotherInLawAndArrayOfExcerptFromBookWithMoMotherOrMotherInOnLastLine = {
"SearchTerm": "mo-?ther-in-law",
"Results": [
{
"ISBN": "0123456789123",
"Page": 0,
"Line": 1
}
]
}
/*
_ _ _ _ ___ _____ _____ _____ ____ _____ ____
| | | | \ | |_ _|_ _| |_ _| ____/ ___|_ _/ ___|
| | | | \| || | | | | | | _| \___ \ | | \___ \
| |_| | |\ || | | | | | | |___ ___) || | ___) |
\___/|_| \_|___| |_| |_| |_____|____/ |_| |____/
*/
/* We have provided two unit tests. They're really just `if` statements that
* output to the console. We've provided two tests as examples, and
* they should pass with a correct implementation of `findSearchTermInBooks`.
*
* Please add your unit tests below.
* */
/** We can check that, given a known input, we get a known output. */
/* Test 1 */
/** @type {Result} */
const test1result = findSearchTermInBooks("the", twentyLeaguesIn);
if (JSON.stringify(twentyLeaguesOut) === JSON.stringify(test1result)) {
console.log("PASS: Test 1 - Word 'the' is found once on page 31, line 9 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
} else {
console.log("FAIL: Test 1 - Word 'the' is found once on page 31, line 9 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
console.log("Expected:", twentyLeaguesOut);
console.log("Received:", test1result);
}
/** We could choose to check that we get the right number of results. */
/* Test 2 */
/** @type {Result} */
const test2result = findSearchTermInBooks("the", twentyLeaguesIn);
if (test2result.Results.length == 1) {
console.log("PASS: Test 2 - Word \"the\" is found once on page 31, line 9 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
} else {
console.log("FAIL: Test 2 - Word \"the\" is found once on page 31, line 9 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
console.log("Expected:", twentyLeaguesOut.Results.length);
console.log("Received:", test2result.Results.length);
}
/* Test 3 */
/** @type {Result} */
const test3result = findSearchTermInBooks("dark-?ness", twentyLeaguesIn);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermDarknessAndArrayTwentyLeaguesIn) === JSON.stringify(test3result)) {
console.log("PASS: Test 3 - Word \"dark-?ness\" is found once on page 31, line 8 and line 9 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
} else {
console.log("FAIL: Test 3 - Word \"dark-?ness\" is found once on page 31, line 8 and line 9 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermDarknessAndArrayTwentyLeaguesIn);
console.log("Received:", test3result);
}
/* Test 4 */
/** @type {Result} */
const test4result = findSearchTermInBooks("dark-?ness", arrayWithExcerptFromTwentyThousandLeaguesUnderTheSeaWithOneLine);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermDarknessAndArrayWithExcerptFromTwentyThousandLeaguesUnderTheSeaWithOneLine) === JSON.stringify(test4result)) {
console.log("PASS: Test 4 - Beginning of \"dark-?ness\" is found once on page 31, line 8 of excerpt of Twenty Thousand Leagues Under The Sea with 1 line");
} else {
console.log("FAIL: Test 4 - Beginning of \"dark-?ness\" is found once on page 31, line 8 of excerpt of Twenty Thousand Leagues Under The Sea with 1 line");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermDarknessAndArrayWithExcerptFromTwentyThousandLeaguesUnderTheSeaWithOneLine);
console.log("Received:", test4result);
}
/* Test 5 */
/** @type {Result} */
const test5result = findSearchTermInBooks("dark-haired", twentyLeaguesIn);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermDarkHairedAndArrayTwentyLeaguesIn) === JSON.stringify(test5result)) {
console.log("PASS: Test 5 - Word \"dark-haired\" is not found in excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
} else {
console.log("FAIL: Test 5 - Word \"dark-haired\" is not found in excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermDarkHairedAndArrayTwentyLeaguesIn);
console.log("Received:", test5result);
}
/* Test 6 */
/** @type {Result} */
const test6result = findSearchTermInBooks("dark-haired", arrayWithExcerptFromTwentyThousandLeaguesUnderTheSeaWithOneLine);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermDarkHairedAndArrayWithExcerptFromTwentyThousandLeaguesUnderTheSeaWithOneLine) === JSON.stringify(test6result)) {
console.log("PASS: Test 6 - Beginning of \"dark-haired\" is found once on page 31, line 8 of excerpt of Twenty Thousand Leagues Under The Sea with 1 line");
} else {
console.log("FAIL: Test 6 - Beginning of \"dark-haired\" is found once on page 31, line 8 of excerpt of Twenty Thousand Leagues Under The Sea with 1 line");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermDarkHairedAndArrayWithExcerptFromTwentyThousandLeaguesUnderTheSeaWithOneLine);
console.log("Received:", test6result);
}
/* Test 7 */
/** @type {Result} */
const test7result = findSearchTermInBooks("dark-haired", arrayOfExcerptsFromBooksWithWordDarkHaired);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermDarkHairedAndArrayOfExcerptsFromBooksWithWordDarkHaired) === JSON.stringify(test7result)) {
console.log("PASS: Test 7 - Word \"dark-haired\" is found once on page 31, line 8 of excerpt of Book With Excerpt With First Line Ending With dark- and Second Line Beginning With haired");
} else {
console.log("FAIL: Test 7 - Word \"dark-haired\" is found once on page 31, line 8 of excerpt of Book With Excerpt With First Line Ending With dark- and Second Line Beginning With haired");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermDarkHairedAndArrayOfExcerptsFromBooksWithWordDarkHaired);
console.log("Received:", test7result);
}
/* Test 8 */
/** @type {Result} */
const test8result = findSearchTermInBooks("Ca-?na-?di-?an's", twentyLeaguesIn);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermCanadiansAndTwentyLeaguesIn) === JSON.stringify(test8result)) {
console.log("PASS: Test 8 - Word \"Ca-?na-?di-?an\'s\" is found once on page 31, line 9 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
} else {
console.log("FAIL: Test 8 - Word \"Ca-?na-?di-?an\'s\" is found once on page 31, line 9 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermCanadiansAndTwentyLeaguesIn);
console.log("Received:", test8result);
}
/* Test 9 */
/** @type {Result} */
const test9result = findSearchTermInBooks("the", arrayOfZeroExcerptsFromBooks);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermTheAndArrayOfZeroExcerptsFromBooks) === JSON.stringify(test9result)) {
console.log("PASS: Test 9 - Word \"the\" is not found when there are no excerpts of books");
} else {
console.log("FAIL: Test 9 - Word \"the\" is not found when there are no excerpts of books");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermTheAndArrayOfZeroExcerptsFromBooks);
console.log("Received:", test9result);
}
/* Test 10 */
/** @type {Result} */
const test10result = findSearchTermInBooks("the", arrayOfExcerptFromBookWithNoContent);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermTheAndArrayOfExcerptOfBookWithNoContent) === JSON.stringify(test10result)) {
console.log("PASS: Test 10 - Word \"the\" is not found in an excerpt of a book with no lines");
} else {
console.log("FAIL: Test 10 - Word \"the\" is not found in an excerpt of a book with no lines");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermTheAndArrayOfExcerptOfBookWithNoContent);
console.log("Received:", test10result);
}
/* Test 11 */
/** @type {Result} */
const test11result = findSearchTermInBooks("The", twentyLeaguesIn);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermTheAndArrayTwentyLeaguesIn) === JSON.stringify(test11result)) {
console.log("PASS: Test 11 - Word \"The\" is found once on page 31, line 8 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
} else {
console.log("FAIL: Test 11 - Word \"The\" is found once on page 31, line 8 of excerpt of Twenty Thousand Leagues Under The Sea with 3 lines");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermTheAndArrayTwentyLeaguesIn);
console.log("Received:", test11result);
}
/* Test 12 */
/** @type {Result} */
const test12result = createSearchTermWithOptionalSyllabicPhrases("mo-?ther-in-law");
if (test12result === "mo-?(ther-(in-(law)?)?)?") {
console.log("PASS: Test 12 - createSearchTermWithOptionalSyllabicPhrases(\"mo-?ther-in-law\") returns \"mo-?(ther-(in-(law)?)?)?\"")
}
/* Test 13 */
/** @type {Result} */
const test13result = findSearchTermInBooks("mo-?ther-in-law", arrayOfExcerptFromBookWithMoOnLastLine);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermMotherInLawAndArrayOfExcerptFromBookWithMoMotherOrMotherInOnLastLine) === JSON.stringify(test13result)) {
console.log("PASS: Test 13 - Word \"mo-?ther-in-law\" is found once on page 0, line 1 of excerpt of Book With Excerpt With Mo- On Last Line");
} else {
console.log("FAIL: Test 13 - Word \"mo-?ther-in-law\" is found once on page 0, line 1 of excerpt of Book With Excerpt With Mo- On Last Line");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermMotherInLawAndArrayOfExcerptFromBookWithMoMotherOrMotherInOnLastLine);
console.log("Received:", test13result);
}
/* Test 14 */
/** @type {Result} */
const test14result = findSearchTermInBooks("mo-?ther-in-law", arrayOfExcerptFromBookWithMotherOnLastLine);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermMotherInLawAndArrayOfExcerptFromBookWithMoMotherOrMotherInOnLastLine) === JSON.stringify(test14result)) {
console.log("PASS: Test 14 - Word \"mo-?ther-in-law\" is found once on page 0, line 1 of excerpt of Book With Excerpt With Mother- On Last Line");
} else {
console.log("FAIL: Test 14 - Word \"mo-?ther-in-law\" is found once on page 0, line 1 of excerpt of Book With Excerpt With Mother- On Last Line");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermMotherInLawAndArrayOfExcerptFromBookWithMoMotherOrMotherInOnLastLine);
console.log("Received:", test14result);
}
/* Test 15 */
/** @type {Result} */
const test15result = findSearchTermInBooks("mo-?ther-in-law", arrayOfExcerptFromBookWithMotherInOnLastLine);
if (JSON.stringify(outputOfFindSearchTermInBooksForSearchTermMotherInLawAndArrayOfExcerptFromBookWithMoMotherOrMotherInOnLastLine) === JSON.stringify(test15result)) {
console.log("PASS: Test 15 - Word \"mo-?ther-in-law\" is found once on page 0, line 1 of excerpt of Book With Excerpt With Mother-In- On Last Line");
} else {
console.log("FAIL: Test 15 - Word \"mo-?ther-in-law\" is found once on page 0, line 1 of excerpt of Book With Excerpt With Mother-In- On Last Line");
console.log("Expected:", outputOfFindSearchTermInBooksForSearchTermMotherInLawAndArrayOfExcerptFromBookWithMoMotherOrMotherInOnLastLine);
console.log("Received:", test15result);
}