// If using TypeScript, ensure Jest types are available // This import is only necessary if your environment does not provide 'expect' globally import { describe, expect, it } from '@jest/globals'; import { getCoordinatesFromZip, SAN_DIEGO_ZIP_COORDINATES } from './location'; import { LIBRARY_LOCATIONS } from './library-locations'; // Convert the object to an array of coordinates for testing const LIBRARY_LOCATIONS_ARRAY = Object.values(LIBRARY_LOCATIONS); const ZIP_COORDS = Object.entries(SAN_DIEGO_ZIP_COORDINATES || {}); describe('San Diego ZIP and Library Coordinates', () => { it('all ZIP code lat/lngs are unique', () => { const seen = new Map(); let duplicate = null; for (const [zip, coord] of ZIP_COORDS) { const { lat, lng } = coord as { lat: number; lng: number }; const key = `${lat},${lng}`; if (seen.has(key)) { duplicate = { zip, other: seen.get(key), lat, lng }; break; } seen.set(key, zip); } if (duplicate) { throw new Error(`Duplicate ZIP coordinates: ${duplicate.zip} and ${duplicate.other} share (${duplicate.lat}, ${duplicate.lng})`); } expect(duplicate).toBe(null); }); it('all library lat/lngs are unique', () => { const seen = new Map(); let duplicate = null; for (let i = 0; i < LIBRARY_LOCATIONS_ARRAY.length; i++) { const coord = LIBRARY_LOCATIONS_ARRAY[i]; const key = `${coord.lat},${coord.lng}`; if (seen.has(key)) { duplicate = { idx: i, other: seen.get(key), lat: coord.lat, lng: coord.lng }; break; } seen.set(key, i); } if (duplicate) { throw new Error(`Duplicate library coordinates: index ${duplicate.idx} and ${duplicate.other} share (${duplicate.lat}, ${duplicate.lng})`); } expect(duplicate).toBe(null); }); it('no ZIP code lat/lng matches any library lat/lng', () => { const librarySet = new Set(LIBRARY_LOCATIONS_ARRAY.map((c: { lat: number; lng: number }) => `${c.lat},${c.lng}`)); let conflict = null; for (const [zip, coord] of ZIP_COORDS) { const { lat, lng } = coord as { lat: number; lng: number }; const key = `${lat},${lng}`; if (librarySet.has(key)) { conflict = { zip, lat, lng }; break; } } if (conflict) { throw new Error(`ZIP code ${conflict.zip} shares coordinates (${conflict.lat}, ${conflict.lng}) with a library`); } expect(conflict).toBe(null); }); it("'92129' has the expected coordinates", () => { const coord = getCoordinatesFromZip('92129'); expect(coord).toEqual({ lat: 32.9584, lng: -117.1253 }); }); });