MCPcopy
hub / github.com/golang/geo / TestCellIDDistanceToBegin

Function TestCellIDDistanceToBegin

s2/cellid_test.go:602–643  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

600}
601
602func TestCellIDDistanceToBegin(t *testing.T) {
603 tests := []struct {
604 id CellID
605 want int64
606 }{
607 {
608 // at level 0 (i.e. full faces), there are only 6 cells from
609 // the last face to the beginning of the Hilbert curve.
610 id: CellIDFromFace(5).ChildEndAtLevel(0),
611 want: 6,
612 },
613 {
614 // from the last cell on the last face at the smallest cell size,
615 // there are the maximum number of possible cells.
616 id: CellIDFromFace(5).ChildEndAtLevel(MaxLevel),
617 want: 6 * (1 << uint(2*MaxLevel)),
618 },
619 {
620 // from the first cell on the first face.
621 id: CellIDFromFace(0).ChildBeginAtLevel(0),
622 want: 0,
623 },
624 {
625 // from the first cell at the smallest level on the first face.
626 id: CellIDFromFace(0).ChildBeginAtLevel(MaxLevel),
627 want: 0,
628 },
629 }
630
631 for _, test := range tests {
632 if got := test.id.distanceFromBegin(); got != test.want {
633 t.Errorf("%v.distanceToBegin() = %v, want %v", test.id, got, test.want)
634 }
635 }
636
637 // Test that advancing from the beginning by the distance from a cell gets
638 // us back to that cell.
639 id := CellIDFromFacePosLevel(3, 0x12345678, MaxLevel-4)
640 if got := CellIDFromFace(0).ChildBeginAtLevel(id.Level()).Advance(id.distanceFromBegin()); got != id {
641 t.Errorf("advancing from the beginning by the distance of a cell should return us to that cell. got %v, want %v", got, id)
642 }
643}
644
645func TestCellIDWrapping(t *testing.T) {
646 id := CellIDFromFacePosLevel(3, 0x12345678, MaxLevel-4)

Callers

nothing calls this directly

Calls 7

CellIDFromFaceFunction · 0.85
CellIDFromFacePosLevelFunction · 0.85
ChildEndAtLevelMethod · 0.80
ChildBeginAtLevelMethod · 0.80
distanceFromBeginMethod · 0.80
AdvanceMethod · 0.45
LevelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…