diff options
| author | Your Name <you@example.com> | 2026-05-17 01:31:49 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-17 01:31:49 +0530 |
| commit | 347d29658959c7e4b368a15134c183f4ce7a25bc (patch) | |
| tree | 362b3e40273e3c1435bdd0745de61006041bb803 /main/geohash.c | |
| parent | 4c47ae188b288e7d24bd9566ab3e6a6805d9484f (diff) | |
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)
Diffstat (limited to 'main/geohash.c')
| -rw-r--r-- | main/geohash.c | 8 |
1 files changed, 5 insertions, 3 deletions
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) | |||
| 38 | for (int i = 0; i < precision; i++) { | 38 | for (int i = 0; i < precision; i++) { |
| 39 | int byte_idx = (i * 5) / 8; | 39 | int byte_idx = (i * 5) / 8; |
| 40 | int bit_offset = (i * 5) % 8; | 40 | int bit_offset = (i * 5) % 8; |
| 41 | uint16_t val = (hash_bytes[byte_idx] << 8); | 41 | uint32_t val = ((uint32_t)hash_bytes[byte_idx] << 16); |
| 42 | if (byte_idx + 1 < (int)sizeof(hash_bytes)) | 42 | if (byte_idx + 1 < (int)sizeof(hash_bytes)) |
| 43 | val |= hash_bytes[byte_idx + 1]; | 43 | val |= ((uint32_t)hash_bytes[byte_idx + 1] << 8); |
| 44 | val = (val >> (16 - 5 - bit_offset)) & 0x1F; | 44 | if (byte_idx + 2 < (int)sizeof(hash_bytes)) |
| 45 | val |= hash_bytes[byte_idx + 2]; | ||
| 46 | val = (val >> (24 - 5 - bit_offset)) & 0x1F; | ||
| 45 | out[i] = BASE32[val]; | 47 | out[i] = BASE32[val]; |
| 46 | } | 48 | } |
| 47 | out[precision] = '\0'; | 49 | out[precision] = '\0'; |