@@ -609,6 +609,7 @@ func TestPentagons(t *testing.T) {
609609 t .Parallel ()
610610
611611 for _ , res := range []int {0 , 8 , 15 } {
612+ res := res
612613 t .Run (fmt .Sprintf ("res=%d" , res ), func (t * testing.T ) {
613614 t .Parallel ()
614615 pentagons := Pentagons (res )
@@ -621,6 +622,83 @@ func TestPentagons(t *testing.T) {
621622 }
622623}
623624
625+ func TestCellToVertex (t * testing.T ) {
626+ t .Parallel ()
627+
628+ testCases := []struct {
629+ cell Cell
630+ expectedVertex Cell
631+ vertexNum int
632+ }{
633+ {cell : validCell , expectedVertex : 0x2050dab63fffffff , vertexNum : 0 },
634+ {cell : validCell , expectedVertex : 0 , vertexNum : 6 }, // vertex num should be between 0 and 5 for hexagonal cells.
635+ }
636+
637+ for i , tc := range testCases {
638+ tc := tc
639+
640+ t .Run (fmt .Sprint (i ), func (t * testing.T ) {
641+ t .Parallel ()
642+
643+ vertex := CellToVertex (tc .cell , tc .vertexNum )
644+ assertEqual (t , tc .expectedVertex , vertex )
645+ })
646+ }
647+ }
648+
649+ func TestCellToVertexes (t * testing.T ) {
650+ t .Parallel ()
651+
652+ testCases := []struct {
653+ cell Cell
654+ numVertexes int
655+ }{
656+ {cell : validCell , numVertexes : 6 },
657+ {cell : pentagonCell , numVertexes : 5 },
658+ {cell : - 1 , numVertexes : 0 }, // Invalid cel.
659+ }
660+
661+ for _ , tc := range testCases {
662+ tc := tc
663+ t .Run (fmt .Sprint (tc .numVertexes ), func (t * testing.T ) {
664+ t .Parallel ()
665+
666+ vertexes := CellToVertexes (tc .cell )
667+ assertEqual (t , tc .numVertexes , len (vertexes ))
668+ })
669+ }
670+ }
671+
672+ func TestVertexToLatLng (t * testing.T ) {
673+ t .Parallel ()
674+
675+ testCases := []struct {
676+ vertex Cell
677+ expectedLatLng LatLng
678+ }{
679+ {vertex : CellToVertex (validCell , 0 ), expectedLatLng : LatLng {Lat : 67.22475 , Lng : - 168.52301 }},
680+ {vertex : - 1 , expectedLatLng : LatLng {}}, // Invalid vertex.
681+ }
682+
683+ for i , tc := range testCases {
684+ tc := tc
685+
686+ t .Run (fmt .Sprint (i ), func (t * testing.T ) {
687+ t .Parallel ()
688+
689+ latLng := VertexToLatLng (tc .vertex )
690+ assertEqualLatLng (t , tc .expectedLatLng , latLng )
691+ })
692+ }
693+ }
694+
695+ func TestIsValidVertex (t * testing.T ) {
696+ t .Parallel ()
697+
698+ assertFalse (t , IsValidVertex (0 ))
699+ assertTrue (t , IsValidVertex (2473183460575936511 ))
700+ }
701+
624702func equalEps (expected , actual float64 ) bool {
625703 return math .Abs (expected - actual ) < eps
626704}
0 commit comments