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).

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.

2 participants