mirror of https://github.com/go-gorm/gorm.git
Add test for float64 precision
This commit is contained in:
parent
2b36ccddd0
commit
1ff630f3d5
|
@ -28,7 +28,7 @@ func (d *postgres) SqlTag(column interface{}, size int) string {
|
||||||
case int64, uint64, sql.NullInt64:
|
case int64, uint64, sql.NullInt64:
|
||||||
return "bigint"
|
return "bigint"
|
||||||
case float32, float64, sql.NullFloat64:
|
case float32, float64, sql.NullFloat64:
|
||||||
return "double precision"
|
return "numeric"
|
||||||
case []byte:
|
case []byte:
|
||||||
return "bytea"
|
return "bytea"
|
||||||
case string, sql.NullString:
|
case string, sql.NullString:
|
||||||
|
|
18
gorm_test.go
18
gorm_test.go
|
@ -29,6 +29,7 @@ type User struct {
|
||||||
ShippingAddressId int64 // Embedded struct's foreign key
|
ShippingAddressId int64 // Embedded struct's foreign key
|
||||||
When time.Time
|
When time.Time
|
||||||
CreditCard CreditCard
|
CreditCard CreditCard
|
||||||
|
Latitude float64
|
||||||
PasswordHash []byte
|
PasswordHash []byte
|
||||||
IgnoreMe int64 `sql:"-"`
|
IgnoreMe int64 `sql:"-"`
|
||||||
}
|
}
|
||||||
|
@ -159,6 +160,22 @@ func TestFirstAndLast(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrecision(t *testing.T) {
|
||||||
|
f := 35.03554004971999
|
||||||
|
user := User{Name: "Precision", Latitude: f}
|
||||||
|
db.Save(&user)
|
||||||
|
if user.Latitude != f {
|
||||||
|
t.Errorf("Float64 should not be changed after save")
|
||||||
|
}
|
||||||
|
|
||||||
|
var u User
|
||||||
|
db.First(&u, "name = ?", "Precision")
|
||||||
|
fmt.Println(u.Latitude)
|
||||||
|
if u.Latitude != f {
|
||||||
|
t.Errorf("Float64 should not be changed after query")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateAndUpdate(t *testing.T) {
|
func TestCreateAndUpdate(t *testing.T) {
|
||||||
name, name2, new_name := "update", "update2", "new_update"
|
name, name2, new_name := "update", "update2", "new_update"
|
||||||
user := User{Name: name, Age: 1, PasswordHash: []byte{'f', 'a', 'k', '4'}}
|
user := User{Name: name, Age: 1, PasswordHash: []byte{'f', 'a', 'k', '4'}}
|
||||||
|
@ -1111,6 +1128,7 @@ func TestNot(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Not(User{Name: "3"}).Find(&users5)
|
db.Not(User{Name: "3"}).Find(&users5)
|
||||||
|
|
||||||
if len(users1)-len(users5) != int(name_3_count) {
|
if len(users1)-len(users5) != int(name_3_count) {
|
||||||
t.Errorf("Should find all users's name not equal 3")
|
t.Errorf("Should find all users's name not equal 3")
|
||||||
}
|
}
|
||||||
|
|
2
utils.go
2
utils.go
|
@ -90,6 +90,8 @@ func isBlank(value reflect.Value) bool {
|
||||||
switch value.Kind() {
|
switch value.Kind() {
|
||||||
case reflect.Int, reflect.Int64, reflect.Int32:
|
case reflect.Int, reflect.Int64, reflect.Int32:
|
||||||
return value.Int() == 0
|
return value.Int() == 0
|
||||||
|
case reflect.Float32, reflect.Float64:
|
||||||
|
return value.Float() == 0
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
return value.String() == ""
|
return value.String() == ""
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
|
|
Loading…
Reference in New Issue