refactor: Clean up code by removing unnecessary whitespace and improving readability

This commit is contained in:
Van Leemput Dayron
2025-11-05 07:55:05 +01:00
parent 9cb21c3470
commit 30dca05e15
8 changed files with 605 additions and 446 deletions

View File

@@ -11,42 +11,47 @@ void main() {
{'width': 1200, 'height': 800, 'photo_reference': 'horizontal_hd'},
{'width': 600, 'height': 400, 'photo_reference': 'horizontal2'},
];
// Appliquer l'algorithme de tri de qualité
photos.sort((a, b) => _sortPhotosByQuality(a, b));
// Vérifications
expect(photos.first['photo_reference'], 'horizontal_hd');
expect(photos.first['width'], 1200);
expect(photos.first['height'], 800);
// La photo verticale devrait être parmi les dernières
final lastPhotos = photos.sublist(photos.length - 2);
expect(lastPhotos.any((p) => p['photo_reference'] == 'vertical1'), true);
print('Photos triées par qualité (meilleure en premier):');
for (var photo in photos) {
final width = photo['width'] as int;
final height = photo['height'] as int;
final ratio = width / height;
final resolution = width * height;
print('${photo['photo_reference']}: ${width}x${height} '
'(ratio: ${ratio.toStringAsFixed(2)}, résolution: $resolution)');
print(
'${photo['photo_reference']}: ${width}x$height '
'(ratio: ${ratio.toStringAsFixed(2)}, résolution: $resolution)',
);
}
});
test('should generate correct search terms for Paris', () {
final searchTerms = _generateSearchTerms('Paris');
// Vérifier que les termes spécifiques à Paris sont présents
expect(searchTerms.any((term) => term.contains('Tour Eiffel')), true);
expect(searchTerms.any((term) => term.contains('Arc de Triomphe')), true);
expect(searchTerms.any((term) => term.contains('Notre-Dame')), true);
// Vérifier que les termes génériques sont aussi présents
expect(searchTerms.any((term) => term.contains('attractions touristiques')), true);
expect(
searchTerms.any((term) => term.contains('attractions touristiques')),
true,
);
expect(searchTerms.any((term) => term.contains('landmarks')), true);
print('Termes de recherche pour Paris:');
for (var term in searchTerms) {
print('- $term');
@@ -55,12 +60,12 @@ void main() {
test('should generate correct search terms for London', () {
final searchTerms = _generateSearchTerms('London');
// Vérifier que les termes spécifiques à Londres sont présents
expect(searchTerms.any((term) => term.contains('Big Ben')), true);
expect(searchTerms.any((term) => term.contains('Tower Bridge')), true);
expect(searchTerms.any((term) => term.contains('London Eye')), true);
print('Termes de recherche pour Londres:');
for (var term in searchTerms) {
print('- $term');
@@ -69,15 +74,18 @@ void main() {
test('should handle unknown cities gracefully', () {
final searchTerms = _generateSearchTerms('Petite Ville Inconnue');
// Devrait au moins avoir des termes génériques
expect(searchTerms.isNotEmpty, true);
expect(searchTerms.any((term) => term.contains('attractions touristiques')), true);
expect(
searchTerms.any((term) => term.contains('attractions touristiques')),
true,
);
expect(searchTerms.any((term) => term.contains('landmarks')), true);
// Le terme original devrait être en dernier
expect(searchTerms.last, 'Petite Ville Inconnue');
print('Termes de recherche pour ville inconnue:');
for (var term in searchTerms) {
print('- $term');
@@ -92,39 +100,39 @@ int _sortPhotosByQuality(Map<String, dynamic> a, Map<String, dynamic> b) {
final aHeight = a['height'] as int;
final bWidth = b['width'] as int;
final bHeight = b['height'] as int;
final aRatio = aWidth / aHeight;
final bRatio = bWidth / bHeight;
// 1. Privilégier les photos horizontales (ratio > 1)
if (aRatio > 1 && bRatio <= 1) return -1;
if (bRatio > 1 && aRatio <= 1) return 1;
// 2. Si les deux sont horizontales ou les deux ne le sont pas,
// privilégier la résolution plus élevée
final aResolution = aWidth * aHeight;
final bResolution = bWidth * bHeight;
if (aResolution != bResolution) {
return bResolution.compareTo(aResolution);
}
// 3. En cas d'égalité de résolution, privilégier le meilleur ratio (plus proche de 1.5)
final idealRatio = 1.5;
final aDiff = (aRatio - idealRatio).abs();
final bDiff = (bRatio - idealRatio).abs();
return aDiff.compareTo(bDiff);
}
/// Reproduit l'algorithme de génération de termes de recherche
List<String> _generateSearchTerms(String location) {
final terms = <String>[];
// Ajouter des termes spécifiques pour les villes connues
final citySpecificTerms = _getCitySpecificTerms(location.toLowerCase());
terms.addAll(citySpecificTerms);
// Termes génériques avec attractions
terms.addAll([
'$location attractions touristiques monuments',
@@ -136,14 +144,14 @@ List<String> _generateSearchTerms(String location) {
'$location skyline',
location, // Terme original en dernier
]);
return terms;
}
/// Reproduit les termes spécifiques pour des villes connues
List<String> _getCitySpecificTerms(String location) {
final specific = <String>[];
if (location.contains('paris')) {
specific.addAll([
'Tour Eiffel Paris',
@@ -182,6 +190,6 @@ List<String> _getCitySpecificTerms(String location) {
'Tokyo Skytree',
]);
}
return specific;
}
}