summaryrefslogtreecommitdiff
path: root/src/pkg/testing/quick
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-02-14 13:23:51 +0100
committerOndřej Surý <ondrej@sury.org>2011-02-14 13:23:51 +0100
commit758ff64c69e34965f8af5b2d6ffd65e8d7ab2150 (patch)
tree6d6b34f8c678862fe9b56c945a7b63f68502c245 /src/pkg/testing/quick
parent3e45412327a2654a77944249962b3652e6142299 (diff)
downloadgolang-upstream/2011-02-01.1.tar.gz
Imported Upstream version 2011-02-01.1upstream/2011-02-01.1
Diffstat (limited to 'src/pkg/testing/quick')
-rw-r--r--src/pkg/testing/quick/quick.go16
-rw-r--r--src/pkg/testing/quick/quick_test.go7
2 files changed, 12 insertions, 11 deletions
diff --git a/src/pkg/testing/quick/quick.go b/src/pkg/testing/quick/quick.go
index 0b1659725..a5568b048 100644
--- a/src/pkg/testing/quick/quick.go
+++ b/src/pkg/testing/quick/quick.go
@@ -60,18 +60,16 @@ func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) {
switch concrete := t.(type) {
case *reflect.BoolType:
return reflect.NewValue(rand.Int()&1 == 0), true
- case *reflect.FloatType, *reflect.IntType, *reflect.UintType:
+ case *reflect.FloatType, *reflect.IntType, *reflect.UintType, *reflect.ComplexType:
switch t.Kind() {
case reflect.Float32:
return reflect.NewValue(randFloat32(rand)), true
case reflect.Float64:
return reflect.NewValue(randFloat64(rand)), true
- case reflect.Float:
- if t.Size() == 4 {
- return reflect.NewValue(float(randFloat32(rand))), true
- } else {
- return reflect.NewValue(float(randFloat64(rand))), true
- }
+ case reflect.Complex64:
+ return reflect.NewValue(complex(randFloat32(rand), randFloat32(rand))), true
+ case reflect.Complex128:
+ return reflect.NewValue(complex(randFloat64(rand), randFloat64(rand))), true
case reflect.Int16:
return reflect.NewValue(int16(randInt64(rand))), true
case reflect.Int32:
@@ -157,7 +155,7 @@ type Config struct {
MaxCount int
// MaxCountScale is a non-negative scale factor applied to the default
// maximum. If zero, the default is unchanged.
- MaxCountScale float
+ MaxCountScale float64
// If non-nil, rand is a source of random numbers. Otherwise a default
// pseudo-random source will be used.
Rand *rand.Rand
@@ -183,7 +181,7 @@ func (c *Config) getMaxCount() (maxCount int) {
maxCount = c.MaxCount
if maxCount == 0 {
if c.MaxCountScale != 0 {
- maxCount = int(c.MaxCountScale * float(*defaultMaxCount))
+ maxCount = int(c.MaxCountScale * float64(*defaultMaxCount))
} else {
maxCount = *defaultMaxCount
}
diff --git a/src/pkg/testing/quick/quick_test.go b/src/pkg/testing/quick/quick_test.go
index c7bff962b..b126e4a16 100644
--- a/src/pkg/testing/quick/quick_test.go
+++ b/src/pkg/testing/quick/quick_test.go
@@ -17,7 +17,9 @@ func fFloat32(a float32) float32 { return a }
func fFloat64(a float64) float64 { return a }
-func fFloat(a float) float { return a }
+func fComplex64(a complex64) complex64 { return a }
+
+func fComplex128(a complex128) complex128 { return a }
func fInt16(a int16) int16 { return a }
@@ -71,7 +73,8 @@ func TestCheckEqual(t *testing.T) {
reportError("fBool", CheckEqual(fBool, fBool, nil), t)
reportError("fFloat32", CheckEqual(fFloat32, fFloat32, nil), t)
reportError("fFloat64", CheckEqual(fFloat64, fFloat64, nil), t)
- reportError("fFloat", CheckEqual(fFloat, fFloat, nil), t)
+ reportError("fComplex64", CheckEqual(fComplex64, fComplex64, nil), t)
+ reportError("fComplex128", CheckEqual(fComplex128, fComplex128, nil), t)
reportError("fInt16", CheckEqual(fInt16, fInt16, nil), t)
reportError("fInt32", CheckEqual(fInt32, fInt32, nil), t)
reportError("fInt64", CheckEqual(fInt64, fInt64, nil), t)