test/search/radical_search: init
This commit is contained in:
74
test/search/radical_search_test.dart
Normal file
74
test/search/radical_search_test.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:jadb/const_data/radicals.dart';
|
||||
import 'package:jadb/search.dart';
|
||||
import 'package:jadb/table_names/radkfile.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'setup_database_connection.dart';
|
||||
|
||||
void main() {
|
||||
test('All constant radicals should exist in the database', () async {
|
||||
final connection = await setupDatabaseConnection();
|
||||
final allRadicalsInDb = await connection.query(
|
||||
RADKFILETableNames.radkfile,
|
||||
columns: ['radical'],
|
||||
distinct: true,
|
||||
);
|
||||
|
||||
final radicalsInDb = allRadicalsInDb
|
||||
.map((e) => e['radical'] as String)
|
||||
.toSet();
|
||||
|
||||
final missingRadicals = radicals.values.flattenedToSet.difference(
|
||||
radicalsInDb,
|
||||
);
|
||||
|
||||
expect(
|
||||
missingRadicals,
|
||||
isEmpty,
|
||||
reason: 'Missing radicals in database: $missingRadicals',
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'All radicals in database should be in the constant radical list',
|
||||
() async {
|
||||
final connection = await setupDatabaseConnection();
|
||||
final allRadicalsInDb = await connection.query(
|
||||
RADKFILETableNames.radkfile,
|
||||
columns: ['radical'],
|
||||
distinct: true,
|
||||
);
|
||||
|
||||
final radicalsInDb = allRadicalsInDb
|
||||
.map((e) => e['radical'] as String)
|
||||
.toSet();
|
||||
|
||||
final extraRadicals = radicalsInDb.difference(
|
||||
radicals.values.flattenedToSet,
|
||||
);
|
||||
|
||||
expect(
|
||||
extraRadicals,
|
||||
isEmpty,
|
||||
reason:
|
||||
'Extra radicals in database missing in the constant list: $extraRadicals',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
group(
|
||||
'All radicals should return results',
|
||||
() {
|
||||
for (final radical in radicals.values.flattened) {
|
||||
test(' - $radical', () async {
|
||||
final connection = await setupDatabaseConnection();
|
||||
final result = await connection.jadbSearchKanjiByRadicals([radical]);
|
||||
expect(result, isNotEmpty);
|
||||
});
|
||||
}
|
||||
},
|
||||
skip:
|
||||
'These will be automatically fixed once the other radical tests are passing',
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user