From 347d29658959c7e4b368a15134c183f4ce7a25bc Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 17 May 2026 01:31:49 +0530 Subject: Testing infrastructure: AGENTS.md rules + unit test framework + geohash tests (11/11 pass) - Add AGENTS.md: full project context + mandatory testing rules for AI sessions - Add tests/unit/ with host-compiled C unit test infrastructure - Clean stubs approach: ESP-IDF type stubs in tests/unit/stubs/, no source modifications - Fix geohash.c bit extraction bug (3-byte span) found by unit tests - test_geohash: 11/11 passing with reference vectors (Munich, NYC, origin, boundaries) --- main/geohash.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'main') diff --git a/main/geohash.c b/main/geohash.c index f649824..dd0e29d 100644 --- a/main/geohash.c +++ b/main/geohash.c @@ -38,10 +38,12 @@ void geohash_encode(double lat, double lon, int precision, char *out) for (int i = 0; i < precision; i++) { int byte_idx = (i * 5) / 8; int bit_offset = (i * 5) % 8; - uint16_t val = (hash_bytes[byte_idx] << 8); + uint32_t val = ((uint32_t)hash_bytes[byte_idx] << 16); if (byte_idx + 1 < (int)sizeof(hash_bytes)) - val |= hash_bytes[byte_idx + 1]; - val = (val >> (16 - 5 - bit_offset)) & 0x1F; + val |= ((uint32_t)hash_bytes[byte_idx + 1] << 8); + if (byte_idx + 2 < (int)sizeof(hash_bytes)) + val |= hash_bytes[byte_idx + 2]; + val = (val >> (24 - 5 - bit_offset)) & 0x1F; out[i] = BASE32[val]; } out[precision] = '\0'; -- cgit v1.2.3