// Test script for institute geocoder functions // This can be run in the browser console or as a standalone test interface TestCase { name: string address: string expected_coords?: { latitude: number longitude: number } } const testCases: TestCase[] = [ { name: "10 Downing Street, London", address: "10 Downing Street, London", expected_coords: { latitude: 51.5034878, longitude: -0.1276965 } }, { name: "Buckingham Palace, London", address: "Buckingham Palace, London", expected_coords: { latitude: 51.501364, longitude: -0.124432 } }, { name: "Big Ben, London", address: "Big Ben, London", expected_coords: { latitude: 51.499479, longitude: -0.124809 } } ] async function testGeocoding() { console.log("πŸ§ͺ Starting Institute Geocoder Tests...") for (const testCase of testCases) { console.log(`\nπŸ“ Testing: ${testCase.name}`) try { // Test the SearXNG service directly const searchQuery = `!osm ${testCase.address}` const searchUrl = `https://search.kevlarai.com/search?q=${encodeURIComponent(searchQuery)}&format=json` console.log(`πŸ” Searching: ${searchUrl}`) const response = await fetch(searchUrl) if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`) } const data = await response.json() console.log(`πŸ“Š Results: ${data.number_of_results} found`) if (data.results && data.results.length > 0) { const result = data.results[0] const coords = { latitude: parseFloat(result.latitude), longitude: parseFloat(result.longitude) } console.log(`βœ… Coordinates: ${coords.latitude}, ${coords.longitude}`) if (testCase.expected_coords) { const latDiff = Math.abs(coords.latitude - testCase.expected_coords.latitude) const lonDiff = Math.abs(coords.longitude - testCase.expected_coords.longitude) if (latDiff < 0.01 && lonDiff < 0.01) { console.log(`🎯 Accuracy: High (within 0.01 degrees)`) } else if (latDiff < 0.1 && lonDiff < 0.1) { console.log(`🎯 Accuracy: Medium (within 0.1 degrees)`) } else { console.log(`⚠️ Accuracy: Low (difference > 0.1 degrees)`) } } if (result.boundingbox) { console.log(`πŸ—ΊοΈ Bounding Box: ${result.boundingbox.join(', ')}`) } if (result.geojson) { console.log(`πŸ—ΊοΈ GeoJSON: ${result.geojson.type} with ${result.geojson.coordinates?.[0]?.length || 0} points`) } } else { console.log(`❌ No results found`) } } catch (error) { console.error(`❌ Test failed: ${error.message}`) } } console.log("\n🏁 Testing completed!") } // Test address parsing function function testAddressParsing() { console.log("\nπŸ”§ Testing Address Parsing...") const testAddresses = [ { street: "10 Downing Street", town: "London", county: "Greater London", postcode: "SW1A 2AA", country: "United Kingdom" }, { street: "Buckingham Palace", town: "London", county: "Greater London", postcode: "SW1A 1AA", country: "United Kingdom" } ] for (const addr of testAddresses) { const parts = [addr.street, addr.town, addr.county, addr.postcode, addr.country].filter(Boolean) const searchQuery = parts.join(', ') console.log(`πŸ“ Address: ${searchQuery}`) } } // Run tests if this script is executed directly if (typeof window !== 'undefined') { // Browser environment window.testGeocoding = testGeocoding window.testAddressParsing = testAddressParsing console.log("πŸ§ͺ Institute Geocoder tests loaded. Run testGeocoding() or testAddressParsing() to test.") } else { // Node.js environment console.log("πŸ§ͺ Institute Geocoder tests loaded.") } export { testGeocoding, testAddressParsing }