Fix precision loss for test format geometric types

fixes #399
pull/401/head
Jack Christensen 2018-03-17 10:26:03 -05:00
parent a07b87eb8b
commit cb4431028c
14 changed files with 45 additions and 16 deletions

View File

@ -116,8 +116,12 @@ func (src *Box) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
return nil, errUndefined
}
buf = append(buf, fmt.Sprintf(`(%f,%f),(%f,%f)`,
src.P[0].X, src.P[0].Y, src.P[1].X, src.P[1].Y)...)
buf = append(buf, fmt.Sprintf(`(%s,%s),(%s,%s)`,
strconv.FormatFloat(src.P[0].X, 'f', -1, 64),
strconv.FormatFloat(src.P[0].Y, 'f', -1, 64),
strconv.FormatFloat(src.P[1].X, 'f', -1, 64),
strconv.FormatFloat(src.P[1].Y, 'f', -1, 64),
)...)
return buf, nil
}

View File

@ -10,7 +10,7 @@ import (
func TestBoxTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "box", []interface{}{
&pgtype.Box{
P: [2]pgtype.Vec2{{7.1, 5.234}, {3.14, 1.678}},
P: [2]pgtype.Vec2{{7.1, 5.2345678}, {3.14, 1.678}},
Status: pgtype.Present,
},
&pgtype.Box{

View File

@ -103,7 +103,12 @@ func (src *Circle) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
return nil, errUndefined
}
buf = append(buf, fmt.Sprintf(`<(%f,%f),%f>`, src.P.X, src.P.Y, src.R)...)
buf = append(buf, fmt.Sprintf(`<(%s,%s),%s>`,
strconv.FormatFloat(src.P.X, 'f', -1, 64),
strconv.FormatFloat(src.P.Y, 'f', -1, 64),
strconv.FormatFloat(src.R, 'f', -1, 64),
)...)
return buf, nil
}

View File

@ -9,7 +9,7 @@ import (
func TestCircleTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "circle", []interface{}{
&pgtype.Circle{P: pgtype.Vec2{1.234, 5.6789}, R: 3.5, Status: pgtype.Present},
&pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Status: pgtype.Present},
&pgtype.Circle{P: pgtype.Vec2{-1.234, -5.6789}, R: 12.9, Status: pgtype.Present},
&pgtype.Circle{Status: pgtype.Null},
})

View File

@ -101,7 +101,13 @@ func (src *Line) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
return nil, errUndefined
}
return append(buf, fmt.Sprintf(`{%f,%f,%f}`, src.A, src.B, src.C)...), nil
buf = append(buf, fmt.Sprintf(`{%s,%s,%s}`,
strconv.FormatFloat(src.A, 'f', -1, 64),
strconv.FormatFloat(src.B, 'f', -1, 64),
strconv.FormatFloat(src.C, 'f', -1, 64),
)...)
return buf, nil
}
func (src *Line) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {

View File

@ -25,7 +25,7 @@ func TestLineTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "line", []interface{}{
&pgtype.Line{
A: 1.23, B: 4.56, C: 7.89,
A: 1.23, B: 4.56, C: 7.89012345,
Status: pgtype.Present,
},
&pgtype.Line{

View File

@ -116,8 +116,13 @@ func (src *Lseg) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
return nil, errUndefined
}
buf = append(buf, fmt.Sprintf(`(%f,%f),(%f,%f)`,
src.P[0].X, src.P[0].Y, src.P[1].X, src.P[1].Y)...)
buf = append(buf, fmt.Sprintf(`(%s,%s),(%s,%s)`,
strconv.FormatFloat(src.P[0].X, 'f', -1, 64),
strconv.FormatFloat(src.P[0].Y, 'f', -1, 64),
strconv.FormatFloat(src.P[1].X, 'f', -1, 64),
strconv.FormatFloat(src.P[1].Y, 'f', -1, 64),
)...)
return buf, nil
}

View File

@ -10,7 +10,7 @@ import (
func TestLsegTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "lseg", []interface{}{
&pgtype.Lseg{
P: [2]pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}},
P: [2]pgtype.Vec2{{3.14, 1.678}, {7.1, 5.2345678901}},
Status: pgtype.Present,
},
&pgtype.Lseg{

View File

@ -138,7 +138,10 @@ func (src *Path) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
if i > 0 {
buf = append(buf, ',')
}
buf = append(buf, fmt.Sprintf(`(%f,%f)`, p.X, p.Y)...)
buf = append(buf, fmt.Sprintf(`(%s,%s)`,
strconv.FormatFloat(p.X, 'f', -1, 64),
strconv.FormatFloat(p.Y, 'f', -1, 64),
)...)
}
return append(buf, endByte), nil

View File

@ -10,7 +10,7 @@ import (
func TestPathTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "path", []interface{}{
&pgtype.Path{
P: []pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}},
P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}},
Closed: false,
Status: pgtype.Present,
},

View File

@ -98,7 +98,10 @@ func (src *Point) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
return nil, errUndefined
}
return append(buf, fmt.Sprintf(`(%f,%f)`, src.P.X, src.P.Y)...), nil
return append(buf, fmt.Sprintf(`(%s,%s)`,
strconv.FormatFloat(src.P.X, 'f', -1, 64),
strconv.FormatFloat(src.P.Y, 'f', -1, 64),
)...), nil
}
func (src *Point) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {

View File

@ -9,7 +9,7 @@ import (
func TestPointTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "point", []interface{}{
&pgtype.Point{P: pgtype.Vec2{1.234, 5.6789}, Status: pgtype.Present},
&pgtype.Point{P: pgtype.Vec2{1.234, 5.6789012345}, Status: pgtype.Present},
&pgtype.Point{P: pgtype.Vec2{-1.234, -5.6789}, Status: pgtype.Present},
&pgtype.Point{Status: pgtype.Null},
})

View File

@ -125,7 +125,10 @@ func (src *Polygon) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
if i > 0 {
buf = append(buf, ',')
}
buf = append(buf, fmt.Sprintf(`(%f,%f)`, p.X, p.Y)...)
buf = append(buf, fmt.Sprintf(`(%s,%s)`,
strconv.FormatFloat(p.X, 'f', -1, 64),
strconv.FormatFloat(p.Y, 'f', -1, 64),
)...)
}
return append(buf, ')'), nil

View File

@ -10,7 +10,7 @@ import (
func TestPolygonTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "polygon", []interface{}{
&pgtype.Polygon{
P: []pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}, {5.0, 3.234}},
P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}, {5.0, 3.234}},
Status: pgtype.Present,
},
&pgtype.Polygon{