Add test for keeping float precision (#2442)

Add test for keeping float precision
This commit is contained in:
Emir Beganović 2019-05-05 11:56:49 +04:00 committed by GitHub
commit 11caf9f072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -1164,6 +1164,24 @@ func TestCountWithQueryOption(t *testing.T) {
}
}
func TestFloatColumnPrecision(t *testing.T) {
if dialect := os.Getenv("GORM_DIALECT"); dialect != "mysql" && dialect != "sqlite" {
t.Skip()
}
type FloatTest struct {
ID string `gorm:"primary_key"`
FloatValue float64 `gorm:"column:float_value" sql:"type:float(255,5);"`
}
DB.DropTable(&FloatTest{})
DB.AutoMigrate(&FloatTest{})
data := FloatTest{ID: "uuid", FloatValue: 112.57315}
if err := DB.Save(&data).Error; err != nil || data.ID != "uuid" || data.FloatValue != 112.57315 {
t.Errorf("Float value should not lose precision")
}
}
func BenchmarkGorm(b *testing.B) {
b.N = 2000
for x := 0; x < b.N; x++ {