1
0
Fork 0
bocadillo/tests/type_float_test.go

98 lines
1.9 KiB
Go

package tests
import (
"fmt"
"testing"
"github.com/localhots/bocadillo/mysql"
)
func TestFloat(t *testing.T) {
tbl := suite.createTable(mysql.ColumnTypeFloat, "", attrNone)
defer tbl.drop(t)
vals := []float32{
0,
0.1,
0.01,
0.001,
0.0001,
0.00001,
0.000001,
0.0000001,
0.00000001,
1.01,
10.01,
100.001,
1000.0001,
10000.00001,
100000.000001,
1000000.0000001,
99999999.99999999,
999999999.999999999,
9999999999.9999999999,
99999999999.99999999999,
999999999999.999999999999,
9999999999999.9999999999999,
99999999999999.99999999999999,
999999999999999.999999999999999,
123456789012345678901.123456789012345678901,
123456789012345678901234678901234567890.12345678901234567890123456789,
}
for _, v := range vals {
t.Run(fmt.Sprint(v), func(t *testing.T) {
suite.insertAndCompare(t, tbl, v)
})
if v != 0 {
t.Run(fmt.Sprint(-v), func(t *testing.T) {
suite.insertAndCompare(t, tbl, -v)
})
}
}
}
func TestDouble(t *testing.T) {
tbl := suite.createTable(mysql.ColumnTypeDouble, "", attrNone)
defer tbl.drop(t)
vals := []float64{
0,
0.1,
0.01,
0.001,
0.0001,
0.00001,
0.000001,
0.0000001,
0.00000001,
1.01,
10.01,
100.001,
1000.0001,
10000.00001,
100000.000001,
1000000.0000001,
99999999.99999999,
999999999.999999999,
9999999999.9999999999,
99999999999.99999999999,
999999999999.999999999999,
9999999999999.9999999999999,
99999999999999.99999999999999,
999999999999999.999999999999999,
123456789012345678901.123456789012345678901,
123456789012345678901234678901234567890.12345678901234567890123456789,
123456789012345678901234678901234567890123456789012345678901234567890.12345678901234567890123456789,
}
for _, v := range vals {
t.Run(fmt.Sprint(v), func(t *testing.T) {
suite.insertAndCompare(t, tbl, v)
})
if v != 0 {
t.Run(fmt.Sprint(-v), func(t *testing.T) {
suite.insertAndCompare(t, tbl, -v)
})
}
}
}