mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-25 16:29:49 -04:00
Add some word_service tests.
This commit is contained in:
parent
057a0180ac
commit
6e48e85de2
@ -37,6 +37,7 @@ DynamicBibleIonic/platforms/android/android.json
|
||||
DynamicBibleIonic/platforms/android/AndroidManifest.xml
|
||||
DynamicBibleIonic/platforms/android/.gitignore
|
||||
DynamicBibleIonic/.idea
|
||||
DynamicBibleIonic/.tmp
|
||||
DynamicBibleIonic/nbproject
|
||||
DynamicBibleIonic/obj
|
||||
DynamicBibleIonic/bin
|
||||
|
12362
DynamicBibleIonic/src/services/word-service.spec.ts
Normal file
12362
DynamicBibleIonic/src/services/word-service.spec.ts
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,13 @@ export class WordService
|
||||
{
|
||||
}
|
||||
|
||||
normalizeQueryString(qry: string): string[]
|
||||
{
|
||||
qry = qry.toLowerCase();
|
||||
// TODO(jeremy): Should we strip punctuation as well?
|
||||
return qry.replace(/'/g, "").replace(/\s+/g, " ").split(" ");
|
||||
}
|
||||
|
||||
getResultAsPromise(qry: string): Promise<WordLookupResult>
|
||||
{
|
||||
return new Promise((resolve, reject) => { resolve(this.getResult(qry)); });
|
||||
@ -16,16 +23,13 @@ export class WordService
|
||||
|
||||
getResult(qry: string): WordLookupResult
|
||||
{
|
||||
qry = qry.toLowerCase();
|
||||
let qs = qry.split(" ");
|
||||
let qs = this.normalizeQueryString(qry);
|
||||
let words = this.buildIndexArray().sort();
|
||||
let results = new Array();
|
||||
|
||||
// Loop through each query term.
|
||||
for (let i = 0; i < qs.length; i++)
|
||||
for (let q of qs)
|
||||
{
|
||||
let q = qs[i].replace("'", ""); // we don't included ticks in our words.
|
||||
|
||||
// For each query term, figure out which xml file it is in, and get it.
|
||||
// getSearchRefs returns an array of references.
|
||||
for (let w = 0; w < words.length; w++)
|
||||
@ -56,10 +60,12 @@ export class WordService
|
||||
return { word: qry, refs: [], status: -1, msg: "No passages found for query: " + qry + "." };
|
||||
|
||||
let shared: string[];
|
||||
if (results.length == 1)
|
||||
if (results.length == 1) {
|
||||
shared = results[0];
|
||||
else
|
||||
}
|
||||
else {
|
||||
shared = this.findSharedSet(results);
|
||||
}
|
||||
|
||||
if (shared == null || shared == undefined || shared.length == 0)
|
||||
return { word: qry, refs: [], status: -1, msg: "No passages found for query: " + qry + "." };
|
||||
@ -359,13 +365,14 @@ export class WordService
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a list of references in string form as a string[] that are shared given a list of lists of references in string form.
|
||||
* Returns a list of references in string form as a string[] that are shared
|
||||
* given a list of lists of references in string form.
|
||||
*/
|
||||
private findSharedSet(results)
|
||||
{
|
||||
// FindSharedSet takes an array of reference arrays, and figures out which references are shared
|
||||
// by all arrays/sets, then returns a single array of references.
|
||||
|
||||
// FindSharedSet takes an array of reference arrays, and figures out
|
||||
// which references are shared by all arrays/sets, then returns a single
|
||||
// array of references.
|
||||
for (let j in results)
|
||||
{
|
||||
let refs = results[j];
|
||||
|
@ -29,7 +29,7 @@ getTestBed().initTestEnvironment(
|
||||
platformBrowserDynamicTesting(),
|
||||
);
|
||||
// Then we find all the tests.
|
||||
let context: any = require.context('./', true, /\.spec\.ts/);
|
||||
let context: any = require.context('./', true, /word-service\.spec\.ts/);
|
||||
// And load the modules.
|
||||
context.keys().map(context);
|
||||
// Finally, start Karma to run the tests.
|
||||
|
Loading…
x
Reference in New Issue
Block a user