Skip to content

Commit

Permalink
fixing off by 1 error -- and adding unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tingold committed Jan 9, 2025
1 parent 7527f32 commit 8f8417d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion majortom/mtgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (g *MajorTomGrid) CellFromId(id string) (*GridCell, error) {

searchId := id
if len(id) > geohashPrecision {
searchId = id[0 : geohashPrecision-1]
searchId = id[0:geohashPrecision]
}

box, err := geohash.Decode(searchId)
Expand Down
9 changes: 8 additions & 1 deletion majortom/mtgrid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,15 @@ func TestOddTile(t *testing.T) {
g := NewGrid(320, true)
cell, err := g.CellFromId("qr330j8p802")
if err != nil {
t.FailNow()
t.Fail()
} else {
t.Logf("Expected: qr330j8p802, Got: %s", cell.Id())
}
cell, err = g.CellFromId("gcp0ywcrhk1t24vzxu52")
if err != nil {
t.Fail()
} else {
t.Logf("Expected: gcp0ywcrhk1, Got: %s", cell.Id())
}

}

0 comments on commit 8f8417d

Please sign in to comment.