Encode decimals as floats without precision loss

This commit is contained in:
2018-11-18 19:02:34 +01:00
parent 68567fad6e
commit c0a153a532
5 changed files with 300 additions and 13 deletions
+8 -9
View File
@@ -19,8 +19,8 @@ func TestDecimal(t *testing.T) {
"99.9",
},
"6,2": {
"0.00",
"1.00",
"0.0",
"1.0",
"1.33",
"10.16",
"620.99",
@@ -28,18 +28,17 @@ func TestDecimal(t *testing.T) {
"9999.99",
},
"10,4": {
"0.0000",
"0.0",
"1.0001",
"1.3301",
"10.1600",
"10.16",
"620.9999",
"500000.0001",
"999999.9999",
},
"30,10": {
// NOTE: At certain length there's undesired zero fill :/
"0000000000000000000.0000000000",
"0000000000000000001.0000000001",
"0.0",
"1.0000000001",
"99999999999999999999.9999999999",
},
}
@@ -51,11 +50,11 @@ func TestDecimal(t *testing.T) {
for _, v := range vals {
t.Run(v, func(t *testing.T) {
suite.insertAndCompare(t, tbl, v)
suite.insertAndCompare(t, tbl, mysql.NewDecimal(v))
})
if !strings.HasPrefix(v, "0") {
t.Run("-"+v, func(t *testing.T) {
suite.insertAndCompare(t, tbl, "-"+v)
suite.insertAndCompare(t, tbl, mysql.NewDecimal("-"+v))
})
}
}
+3 -1
View File
@@ -2,6 +2,7 @@ package tests
import (
"bytes"
"context"
"database/sql"
"encoding/json"
"fmt"
@@ -201,9 +202,10 @@ func (s *testSuite) insertAndCompareExp(t *testing.T, tbl *table, vals, exps []i
func (s *testSuite) expectValue(t *testing.T, tbl *table, exp []interface{}) {
t.Helper()
out := make(chan []interface{})
ctx := context.Background()
go func() {
for {
evt, err := suite.reader.ReadEvent()
evt, err := suite.reader.ReadEvent(ctx)
if err != nil {
t.Errorf("Failed to read event: %v", err)
return