// ignore_for_file: avoid_print import 'package:flutter_test/flutter_test.dart'; void main() { group('Photo Quality Algorithm Tests', () { test('should sort photos by quality (horizontal preference)', () { // Simulation de données de photos avec différents formats final photos = [ {'width': 400, 'height': 600, 'photo_reference': 'vertical1'}, {'width': 800, 'height': 600, 'photo_reference': 'horizontal1'}, {'width': 300, 'height': 300, 'photo_reference': 'square1'}, {'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)', ); } }); 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('landmarks')), true); print('Termes de recherche pour Paris:'); for (var term in searchTerms) { print('- $term'); } }); 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'); } }); 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('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'); } }); }); } /// Reproduit l'algorithme de tri de qualité des photos int _sortPhotosByQuality(Map a, Map b) { final aWidth = a['width'] as int; 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 _generateSearchTerms(String location) { final terms = []; // 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', '$location landmarks', '$location tourist attractions', '$location monuments historiques', '$location points d\'intérêt', '$location centre ville', '$location skyline', location, // Terme original en dernier ]); return terms; } /// Reproduit les termes spécifiques pour des villes connues List _getCitySpecificTerms(String location) { final specific = []; if (location.contains('paris')) { specific.addAll([ 'Tour Eiffel Paris', 'Arc de Triomphe Paris', 'Notre-Dame Paris', 'Louvre Paris', 'Champs-Élysées Paris', ]); } else if (location.contains('london') || location.contains('londres')) { specific.addAll([ 'Big Ben London', 'Tower Bridge London', 'London Eye', 'Buckingham Palace London', 'Tower of London', ]); } else if (location.contains('rome') || location.contains('roma')) { specific.addAll([ 'Colosseum Rome', 'Trevi Fountain Rome', 'Vatican Rome', 'Pantheon Rome', ]); } else if (location.contains('new york') || location.contains('nyc')) { specific.addAll([ 'Statue of Liberty New York', 'Empire State Building New York', 'Times Square New York', 'Brooklyn Bridge New York', ]); } else if (location.contains('tokyo') || location.contains('japon')) { specific.addAll([ 'Tokyo Tower', 'Senso-ji Temple Tokyo', 'Shibuya Crossing Tokyo', 'Tokyo Skytree', ]); } return specific; }