All notes

, 1 min read

Tbilisi is in Georgia, and so is Atlanta

My location rules read "Tbilisi, Georgia" as two countries at once. The fix was to let the city decide, and to flag what cannot be decided.

Three cards. "Tbilisi, Georgia" gives GE, "Atlanta, Georgia" gives US, and a bare "Georgia" gives US as a flagged default.

Last week I finished a tool that sorts job locations into the UK, the US and the EU. It has a page where you can type a place and watch it decide. I clicked the example buttons on that page to check they worked, and one of them was wrong.

#What it did

Typing Tbilisi, Georgia gave two countries at once, the country Georgia and the United States, with low confidence.

The rules were doing something sensible and getting the wrong answer. "Tbilisi" is a city the rules know is in the country Georgia. "Georgia" is also the name of a US state, and the rules knew that too. Two parts of the same string pointed at two countries, so the result was marked as a conflict.

#Why the tests missed it

The tests had that very string in them. I had generated the expected answers by running the code and saving what came out, so the test recorded the bug as the correct behaviour. A test written that way only proves the code still does what it did yesterday.

#The fix

"Georgia" is now treated as genuinely ambiguous, with two candidates and a default:

InputResultWhy
Tbilisi, GeorgiaGE, high confidencethe city is in the country
Atlanta, GeorgiaUS, high confidencethe city is in the state
GeorgiaUS, flagged as ambiguous, medium confidencenothing to decide it, so a default, but say so

The general rule I took from it: when a field can mean two things, record that it is ambiguous rather than quietly picking one. A later step, or a person, can then decide what to do with the flagged ones.

I also added a test for these three whose expected answers are written by hand, from what I know about geography, not copied from the output.