91 lines
2.5 KiB
Dart
91 lines
2.5 KiB
Dart
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
|
|
.map((e) => e.formalVariant)
|
|
.toSet()
|
|
.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.map((e) => e.formalVariant).toSet(),
|
|
);
|
|
|
|
expect(
|
|
extraRadicals,
|
|
isEmpty,
|
|
reason:
|
|
'Extra radicals in database missing in the constant list: $extraRadicals',
|
|
);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'All constant radicals are located in the correct stroke count group',
|
|
() {
|
|
for (final mapEntry in radicals.entries) {
|
|
final strokeCount = mapEntry.key;
|
|
final radicalsInGroup = mapEntry.value;
|
|
for (final radical in radicalsInGroup) {
|
|
expect(
|
|
strokeCount,
|
|
radical.strokeCount,
|
|
reason:
|
|
'Radical ${radical.formalVariant} should have stroke count $strokeCount but has ${radical.strokeCount}',
|
|
);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
|
|
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.formalVariant,
|
|
]);
|
|
expect(result, isNotEmpty);
|
|
});
|
|
}
|
|
});
|
|
}
|