Skip to content

Commit

Permalink
Spatial types stringers to show actual field names (#510)
Browse files Browse the repository at this point in the history
* Spatial types stringers to show actual field names.

---------

Co-authored-by: Stephen Cathcart <stephen.cathcart@neotechnology.com>
  • Loading branch information
stefano-ottolenghi and StephenCathcart authored Aug 8, 2023
1 parent e269782 commit ee7546f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions neo4j/dbtype/spatial.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ type Point3D struct {

// String returns string representation of this point.
func (p Point2D) String() string {
return fmt.Sprintf("Point{srId=%d, x=%f, y=%f}", p.SpatialRefId, p.X, p.Y)
return fmt.Sprintf("Point{SpatialRefId=%d, X=%f, Y=%f}", p.SpatialRefId, p.X, p.Y)
}

// String returns string representation of this point.
func (p Point3D) String() string {
return fmt.Sprintf("Point{srId=%d, x=%f, y=%f, z=%f}", p.SpatialRefId, p.X, p.Y, p.Z)
return fmt.Sprintf("Point{SpatialRefId=%d, X=%f, Y=%f, Z=%f}", p.SpatialRefId, p.X, p.Y, p.Z)
}
4 changes: 2 additions & 2 deletions neo4j/dbtype/spatialtypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestSpatialTypes(t *testing.T) {
t.Run("String representation of Point2D", func(t *testing.T) {
point := Point2D{SpatialRefId: 1, X: 1.0, Y: 2.0}
actual := point.String()
expect := "Point{srId=1, x=1.000000, y=2.000000}"
expect := "Point{SpatialRefId=1, X=1.000000, Y=2.000000}"
if actual != expect {
t.Errorf("Expected %s but was %s", expect, actual)
}
Expand All @@ -36,7 +36,7 @@ func TestSpatialTypes(t *testing.T) {
t.Run("String representation of Point3D", func(t *testing.T) {
point := Point3D{SpatialRefId: 1, X: 1.0, Y: 2.0, Z: 3.0}
actual := point.String()
expect := "Point{srId=1, x=1.000000, y=2.000000, z=3.000000}"
expect := "Point{SpatialRefId=1, X=1.000000, Y=2.000000, Z=3.000000}"
if actual != expect {
t.Errorf("Expected %s but was %s", expect, actual)
}
Expand Down
16 changes: 8 additions & 8 deletions neo4j/test-integration/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestExamples(outer *testing.T) {
fieldCartesian, _ := field.(dbtype.Point2D)

// Serializing
_ = fieldCartesian.String() // Point{srId=7203, x=2.500000, y=-2.000000}
_ = fieldCartesian.String() // Point{SpatialRefId=7203, X=2.500000, Y=-2.000000}

// Acessing members
print(fieldCartesian.X) // 2.500000
Expand All @@ -272,20 +272,20 @@ func TestExamples(outer *testing.T) {
fieldWgs84 := field.(dbtype.Point2D)

// Serializing
_ = fieldWgs84.String() // Point{srId=4326, x=-1.500000, y=1.00000}
_ = fieldWgs84.String() // Point{SpatialRefId=4326, X=-1.500000, Y=1.00000}

// Acessing members
print(fieldWgs84.X) // -1.500000
print(fieldWgs84.Y) // 1.000000
print(fieldWgs84.SpatialRefId) // 4326
// end::geospatial-types-point2d[]

assertEquals(t, fieldCartesian.String(), "Point{srId=7203, x=2.500000, y=-2.000000}")
assertEquals(t, fieldCartesian.String(), "Point{SpatialRefId=7203, X=2.500000, Y=-2.000000}")
assertEquals(t, fieldCartesian.X, cartesian.X)
assertEquals(t, fieldCartesian.Y, cartesian.Y)
assertEquals(t, fieldCartesian.SpatialRefId, cartesian.SpatialRefId)

assertEquals(t, fieldWgs84.String(), "Point{srId=4326, x=-1.500000, y=1.000000}")
assertEquals(t, fieldWgs84.String(), "Point{SpatialRefId=4326, X=-1.500000, Y=1.000000}")
assertEquals(t, fieldWgs84.X, wgs84.X)
assertEquals(t, fieldWgs84.Y, wgs84.Y)
assertEquals(t, fieldWgs84.SpatialRefId, wgs84.SpatialRefId)
Expand Down Expand Up @@ -334,7 +334,7 @@ func TestExamples(outer *testing.T) {
fieldCartesian := field.(dbtype.Point3D)

// Serializing
_ = fieldCartesian.String() // Point{srId=9157, x=2.500000, y=-2.000000, z=2.000000}
_ = fieldCartesian.String() // Point{SpatialRefId=9157, X=2.500000, Y=-2.000000, Z=2.000000}

// Accessing members
print(fieldCartesian.X) // 2.500000
Expand All @@ -347,7 +347,7 @@ func TestExamples(outer *testing.T) {
fieldWgs84 := field.(dbtype.Point3D)

// Serializing
_ = fieldWgs84.String() // Point{srId=4979, x=-1.500000, y=1.00000, z=3.000000}
_ = fieldWgs84.String() // Point{SpatialRefId=4979, X=-1.500000, Y=1.00000, Z=3.000000}

// Accessing members
print(fieldWgs84.X) // -1.500000
Expand All @@ -356,13 +356,13 @@ func TestExamples(outer *testing.T) {
print(fieldWgs84.SpatialRefId) // 4979
// end::geospatial-types-point3d[]

assertEquals(t, fieldCartesian.String(), "Point{srId=9157, x=2.500000, y=-2.000000, z=2.000000}")
assertEquals(t, fieldCartesian.String(), "Point{SpatialRefId=9157, X=2.500000, Y=-2.000000, Z=2.000000}")
assertEquals(t, fieldCartesian.X, cartesian.X)
assertEquals(t, fieldCartesian.Y, cartesian.Y)
assertEquals(t, fieldCartesian.Z, cartesian.Z)
assertEquals(t, fieldCartesian.SpatialRefId, cartesian.SpatialRefId)

assertEquals(t, fieldWgs84.String(), "Point{srId=4979, x=-1.500000, y=1.000000, z=3.000000}")
assertEquals(t, fieldWgs84.String(), "Point{SpatialRefId=4979, X=-1.500000, Y=1.000000, Z=3.000000}")
assertEquals(t, fieldWgs84.X, wgs84.X)
assertEquals(t, fieldWgs84.Y, wgs84.Y)
assertEquals(t, fieldWgs84.Z, wgs84.Z)
Expand Down

0 comments on commit ee7546f

Please sign in to comment.