mirror of https://github.com/knative/pkg.git
Add helpers for float pointers. (#1559)
This commit is contained in:
parent
9c17340fef
commit
9a051b3dec
12
ptr/ptr.go
12
ptr/ptr.go
|
@ -30,6 +30,18 @@ func Int64(i int64) *int64 {
|
|||
return &i
|
||||
}
|
||||
|
||||
// Float32 is a helper for turning floats into pointers for use in
|
||||
// API types that want *float32.
|
||||
func Float32(f float32) *float32 {
|
||||
return &f
|
||||
}
|
||||
|
||||
// Float64 is a helper for turning floats into pointers for use in
|
||||
// API types that want *float64.
|
||||
func Float64(f float64) *float64 {
|
||||
return &f
|
||||
}
|
||||
|
||||
// Bool is a helper for turning bools into pointers for use in
|
||||
// API types that want *bool.
|
||||
func Bool(b bool) *bool {
|
||||
|
|
|
@ -21,9 +21,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
const want = 55
|
||||
|
||||
func TestInt32(t *testing.T) {
|
||||
const want = 55
|
||||
gotPtr := Int32(want)
|
||||
if want != *gotPtr {
|
||||
t.Errorf("Int32() = &%v, wanted %v", *gotPtr, want)
|
||||
|
@ -31,12 +30,29 @@ func TestInt32(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInt64(t *testing.T) {
|
||||
const want = 55
|
||||
gotPtr := Int64(want)
|
||||
if want != *gotPtr {
|
||||
t.Errorf("Int64() = &%v, wanted %v", *gotPtr, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat32(t *testing.T) {
|
||||
const want = 1.25
|
||||
gotPtr := Float32(want)
|
||||
if want != *gotPtr {
|
||||
t.Errorf("Float32() = &%v, wanted %v", *gotPtr, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat64(t *testing.T) {
|
||||
const want = 1.25
|
||||
gotPtr := Float64(want)
|
||||
if want != *gotPtr {
|
||||
t.Errorf("Float64() = &%v, wanted %v", *gotPtr, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBool(t *testing.T) {
|
||||
const want = true
|
||||
gotPtr := Bool(want)
|
||||
|
|
Loading…
Reference in New Issue