Skip to content

Commit

Permalink
Add test for keeping float precision
Browse files Browse the repository at this point in the history
  • Loading branch information
emirb committed May 5, 2019
1 parent 0807818 commit 741cd60
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,20 @@ func TestCountWithQueryOption(t *testing.T) {
}
}

func TestFloatColumnPrecision(t *testing.T) {
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++ {
Expand Down

0 comments on commit 741cd60

Please sign in to comment.