Skip to content

test: Add unit tests for geo utility functions - #89

Open
Vishmayraj wants to merge 1 commit into
OneBusAway:mainfrom
Vishmayraj:test/geo-utils-and-helpers
Open

test: Add unit tests for geo utility functions#89
Vishmayraj wants to merge 1 commit into
OneBusAway:mainfrom
Vishmayraj:test/geo-utils-and-helpers

Conversation

@Vishmayraj

Copy link
Copy Markdown

geo_utils.go had no test coverage. This PR adds geo_utils_test.go
covering:

  • computeBoundingBox: empty input, nil coordinates, single stop,
    multiple stops, mixed valid/nil coordinates
  • isValidLatLon: zero coordinates, valid coordinates, boundary values,
    out-of-range values
  • BoundingBoxStore: set/get, nonexistent server, point inside/outside
    bounding box
  • haversineDistance: same point, known real-world distance

All existing tests continue to pass.

@0xaboomar 0xaboomar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Vishmayraj , thanks for the PR and the work you’ve put into this.

I’ve left a few comments and requested some changes that should be addressed before we proceed with merging. Please take a look and let me know once they’re updated.

// Known great-circle distance: ~3,867 km
dist := haversineDistance(47.6062, -122.3321, 40.7128, -74.0060)
expectedMeters := 3867000.0
marginMeters := 50000.0 // 50km tolerance

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current 50km margin is a bit too loose. The theoretical maximum error for spherical approximations (like Haversine) is roughly 0.5%, which equates to ~19km for this Seattle-to-NY distance.

I suggest tightening the margin to 25km. This is wide enough to cover the 0.5% model discrepancy while being significantly more precise than 50km.

Look at the "Accuracy" note in this source for more details: https://www.movable-type.co.uk/scripts/latlong.html

// go test ./internal/geo/... -v (all tests)
//
// Tests are isolated so failure in any will stand out.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend removing the header comment block (including the Author tag and test instructions). In Go, the filename and the tests themselves should be self-documenting, and Git handles the authorship tracking. This will keep the file cleaner.

}
if bbox.MinLat != 47.60 || bbox.MaxLat != 47.60 {
t.Errorf("Expected only valid stop coordinates, got %v", bbox)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding checks for MinLon and MaxLon as well.

@@ -0,0 +1,199 @@
package geo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these geographic tests are primarily mathematical and completely independent, I suggest adding t.Parallel() to the top of each test function and subtest (t.Run).

@aaronbrethorst

Copy link
Copy Markdown
Member

Code review

Found 1 issue:

  1. The test file imports github.com/jamespfennell/gtfs, which is no longer a dependency of this module. main migrated the GTFS parser to github.com/OneBusAway/go-gtfs in Migrate to oba gtfs #93 (commit 1dabe72); go.mod now lists only github.com/OneBusAway/go-gtfs v1.1.1 and go.sum has no jamespfennell entries at all. As written the package will not build on current main — and even if the old module were re-added, []jamespfennell/gtfs.Stop is a distinct named type from the []OneBusAway/go-gtfs.Stop that computeBoundingBox accepts, so TestComputeBoundingBox would still fail to typecheck. Worth calling out explicitly because GitHub reports this PR as mergeable/clean: the Go workflow has never run on the head commit (only the CLA check is present), so nothing here will surface the break before it lands on main. Rebasing on main and switching the import to remoteGtfs "github.com/OneBusAway/go-gtfs" should be all that is needed — @0xaboomar's guidance on Migrate to oba gtfs #93 was to keep the remoteGtfs alias and change only the module.

import (
"testing"
remoteGtfs "github.com/jamespfennell/gtfs"
)

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

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.

3 participants