search/filter_kanji: keep order when deduplicating
All checks were successful
Build and test / evals (push) Successful in 13m33s
All checks were successful
Build and test / evals (push) Successful in 13m33s
This commit is contained in:
@@ -18,7 +18,15 @@ Future<List<String>> filterKanjiWithDbConnection(
|
||||
.then((value) => value.map((e) => e['literal'] as String).toSet());
|
||||
|
||||
if (deduplicate) {
|
||||
return filteredKanji.toList();
|
||||
final List<String> result = [];
|
||||
final Set<String> seen = {};
|
||||
for (final k in kanji) {
|
||||
if (filteredKanji.contains(k) && !seen.contains(k)) {
|
||||
result.add(k);
|
||||
seen.add(k);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return kanji.where((k) => filteredKanji.contains(k)).toList();
|
||||
}
|
||||
|
||||
@@ -26,4 +26,27 @@ void main() {
|
||||
|
||||
expect(result.join(), '漢字地字');
|
||||
});
|
||||
|
||||
test('Filter kanji - deduplicate', () async {
|
||||
final connection = await setupDatabaseConnection();
|
||||
|
||||
final result = await connection.filterKanji([
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'漢',
|
||||
'字',
|
||||
'地',
|
||||
'字',
|
||||
'か',
|
||||
'な',
|
||||
'.',
|
||||
'!',
|
||||
'@',
|
||||
';',
|
||||
'々',
|
||||
], deduplicate: true);
|
||||
|
||||
expect(result.join(), '漢字地');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user