1
0
Fork 0

Float and double tests

This commit is contained in:
Gregory Eremin 2018-11-08 20:48:57 +01:00
parent c9abb856d5
commit f6fcf11dd0
1 changed files with 97 additions and 0 deletions

97
tests/float_test.go Normal file
View File

@ -0,0 +1,97 @@
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)
})
}
}
}