Skip to content

refactor(city): inject CSV data into get_city and iter_cities (#106)#112

Open
costajohnt wants to merge 2 commits into
da-luce:mainfrom
costajohnt:fix/106-un-hardcode-city-functions
Open

refactor(city): inject CSV data into get_city and iter_cities (#106)#112
costajohnt wants to merge 2 commits into
da-luce:mainfrom
costajohnt:fix/106-un-hardcode-city-functions

Conversation

@costajohnt
Copy link
Copy Markdown

Summary

Un-hardcodes get_city and iter_cities per issue #106. Both functions now take a CSV byte buffer and its length as explicit parameters instead of reading the cities.h globals directly.

  • main.c passes cities, cities_len to both call sites, so end-user behavior is unchanged.
  • test/city_test.c updates to pass the same arguments for all existing tests, confirming the default path still works.

Why

The issue calls out that duplicate-name handling is hard to test when the function only reads from a compiled-in global. The only way to stress it is via the full cities.csv and we can't easily guarantee both orderings of a given name are present.

The new test

test_get_city_duplicate_names feeds two tiny two-row CSV fixtures with a London in each ordering:

London,1000,CA,...          London,8900000,GB,...
London,8900000,GB,...   vs  London,1000,CA,...

and asserts the ~8.9M row wins either way. This would have caught the binary-search regression fixed in PR #79 directly.

Also added test_iter_cities_null_data_should_not_crash since the new parameter adds a new null-handling path.

Test plan

  • meson test -C build city_test — 6/6 pass (was 4/4 before, +2 new)
  • meson test -C build — 8/8 suites pass
  • ./build/astroterm --help — binary still runs
  • No changes to cities.csv or cities.h generation

Closes #106

…e#106)

Both functions now take a data buffer and length instead of reading
from the cities.h globals. main.c passes cities, cities_len so
end-user behavior is unchanged.

The payoff is in tests. A new test_get_city_duplicate_names feeds
a two-row fixture with the same name in both possible orderings
and verifies the higher-population row always wins, which is the
case called out in the issue after PR da-luce#79.

Closes da-luce#106
Reflow iter_cities signature and the test CSV string-literal initializers
so clang-format --check passes under the pinned CI version.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

❌ Patch coverage is 77.77778% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/city.c 52.63% 3 Missing and 6 partials ⚠️
test/city_test.c 91.42% 0 Missing and 3 partials ⚠️
Files with missing lines Coverage Δ
test/city_test.c 86.45% <91.42%> (+0.15%) ⬆️
src/city.c 48.03% <52.63%> (-0.77%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Un-hardcode city functions

1 participant