diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-03-14 22:51:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-14 22:51:20 -0400 |
commit | a52d86a39e9cca620823e3d97d7c129a7abafced (patch) | |
tree | 1e75aef621f21a96a21bdff14ad2e48056ec56d2 /test/test-database.js | |
parent | 07df1e011794f5a77f7fb7da5cd9ea353a8747e2 (diff) |
Dictionary database improvements (#1527)
* Update formatting
* Add _findMultiBulk
* Update implementation of findTermsBySequenceBulk
* Update tests
* Generalize query creation
* Remove _findGenericBulk
* Reduce function creation
* Add more bindings
* Simplify findTermsExactBulk implementation
* Update var names
* Update _findMultiBulk to support multiple index queries
* Update findTermsBulk
* Update getMedia implementation
* Pass data arg to getAll and findFirst to avoid having multiple closures
Diffstat (limited to 'test/test-database.js')
-rw-r--r-- | test/test-database.js | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/test/test-database.js b/test/test-database.js index 40bdc0fd..c36b5b46 100644 --- a/test/test-database.js +++ b/test/test-database.js @@ -292,8 +292,11 @@ async function testTindTermsExactBulk1(database, titles) { { inputs: [ { - termList: ['打', '打つ', '打ち込む'], - readingList: ['だ', 'うつ', 'うちこむ'] + termList: [ + {expression: '打', reading: 'だ'}, + {expression: '打つ', reading: 'うつ'}, + {expression: '打ち込む', reading: 'うちこむ'} + ] } ], expectedResults: { @@ -313,8 +316,11 @@ async function testTindTermsExactBulk1(database, titles) { { inputs: [ { - termList: ['打', '打つ', '打ち込む'], - readingList: ['だ?', 'うつ?', 'うちこむ?'] + termList: [ + {expression: '打', reading: 'だ?'}, + {expression: '打つ', reading: 'うつ?'}, + {expression: '打ち込む', reading: 'うちこむ?'} + ] } ], expectedResults: { @@ -326,8 +332,10 @@ async function testTindTermsExactBulk1(database, titles) { { inputs: [ { - termList: ['打つ', '打つ'], - readingList: ['うつ', 'ぶつ'] + termList: [ + {expression: '打つ', reading: 'うつ'}, + {expression: '打つ', reading: 'ぶつ'} + ] } ], expectedResults: { @@ -344,8 +352,9 @@ async function testTindTermsExactBulk1(database, titles) { { inputs: [ { - termList: ['打つ'], - readingList: ['うちこむ'] + termList: [ + {expression: '打つ', reading: 'うちこむ'} + ] } ], expectedResults: { @@ -357,8 +366,7 @@ async function testTindTermsExactBulk1(database, titles) { { inputs: [ { - termList: [], - readingList: [] + termList: [] } ], expectedResults: { @@ -370,8 +378,8 @@ async function testTindTermsExactBulk1(database, titles) { ]; for (const {inputs, expectedResults} of data) { - for (const {termList, readingList} of inputs) { - const results = await database.findTermsExactBulk(termList, readingList, titles); + for (const {termList} of inputs) { + const results = await database.findTermsExactBulk(termList, titles); assert.strictEqual(results.length, expectedResults.total); for (const [expression, count] of expectedResults.expressions) { assert.strictEqual(countTermsWithExpression(results, expression), count); @@ -520,7 +528,7 @@ async function testFindTermsBySequenceBulk1(database, mainDictionary) { for (const {inputs, expectedResults} of data) { for (const {sequenceList} of inputs) { - const results = await database.findTermsBySequenceBulk(sequenceList, mainDictionary); + const results = await database.findTermsBySequenceBulk(sequenceList.map((query) => ({query, dictionary: mainDictionary}))); assert.strictEqual(results.length, expectedResults.total); for (const [expression, count] of expectedResults.expressions) { assert.strictEqual(countTermsWithExpression(results, expression), count); @@ -773,8 +781,8 @@ async function testDatabase2() { // Error: not prepared await assert.rejects(async () => await dictionaryDatabase.deleteDictionary(title, {rate: 1000}, () => {})); await assert.rejects(async () => await dictionaryDatabase.findTermsBulk(['?'], titles, null)); - await assert.rejects(async () => await dictionaryDatabase.findTermsExactBulk(['?'], ['?'], titles)); - await assert.rejects(async () => await dictionaryDatabase.findTermsBySequenceBulk([1], title)); + await assert.rejects(async () => await dictionaryDatabase.findTermsExactBulk([{expression: '?', reading: '?'}], titles)); + await assert.rejects(async () => await dictionaryDatabase.findTermsBySequenceBulk([{query: 1, dictionary: title}])); await assert.rejects(async () => await dictionaryDatabase.findTermMetaBulk(['?'], titles)); await assert.rejects(async () => await dictionaryDatabase.findTermMetaBulk(['?'], titles)); await assert.rejects(async () => await dictionaryDatabase.findKanjiBulk(['?'], titles)); |