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) --- tests/unit/test_geohash.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/unit/test_geohash.c (limited to 'tests/unit/test_geohash.c') diff --git a/tests/unit/test_geohash.c b/tests/unit/test_geohash.c new file mode 100644 index 0000000..0da81fa --- /dev/null +++ b/tests/unit/test_geohash.c @@ -0,0 +1,40 @@ +#include "test_framework.h" +#include "../../main/geohash.h" +#include + +int main(void) +{ + char buf[16]; + + printf("=== test_geohash ===\n"); + + geohash_encode(48.1351, 11.5820, 9, buf); + ASSERT_EQ_STR("u281zd9z2", buf, "Munich (48.1351, 11.5820) precision 9"); + + geohash_encode(40.7128, -74.0060, 6, buf); + ASSERT(buf[0] == 'd', "NYC starts with 'd'"); + ASSERT(buf[1] == 'r', "NYC second char 'r'"); + ASSERT_EQ_INT(6, (int)strlen(buf), "NYC precision 6 has length 6"); + + geohash_encode(0.0, 0.0, 8, buf); + ASSERT_EQ_STR("s0000000", buf, "Origin (0,0) precision 8"); + + geohash_encode(90.0, 180.0, 5, buf); + ASSERT_EQ_INT(5, (int)strlen(buf), "North pole max lon precision 5"); + + geohash_encode(-90.0, -180.0, 5, buf); + ASSERT_EQ_INT(5, (int)strlen(buf), "South pole min lon precision 5"); + + geohash_encode(48.1351, 11.5820, 1, buf); + ASSERT_EQ_INT(1, (int)strlen(buf), "Precision 1 produces 1 char"); + ASSERT(buf[0] == 'u', "Munich precision 1 = 'u'"); + + geohash_encode(48.1351, 11.5820, 4, buf); + ASSERT_EQ_STR("u281", buf, "Munich precision 4"); + + char buf2[16]; + geohash_encode(48.1351, 11.5820, 9, buf2); + ASSERT_EQ_STR("u281zd9z2", buf2, "Munich determinism check"); + + TEST_SUMMARY(); +} -- cgit v1.2.3