Commit 878d0e1e authored by Adam Langley's avatar Adam Langley

Add a quickcheck package which is a little like the Haskell one of the same

name.

R=rsc
APPROVED=rsc
DELTA=566  (566 added, 0 deleted, 0 changed)
OCL=35974
CL=36111
parent 74aa9dd5
...@@ -5,8 +5,8 @@ bignum.install: fmt.install ...@@ -5,8 +5,8 @@ bignum.install: fmt.install
bufio.install: io.install os.install strconv.install utf8.install bufio.install: io.install os.install strconv.install utf8.install
bytes.install: os.install unicode.install utf8.install bytes.install: os.install unicode.install utf8.install
compress/flate.install: bufio.install bytes.install io.install math.install os.install sort.install strconv.install compress/flate.install: bufio.install bytes.install io.install math.install os.install sort.install strconv.install
compress/gzip.install: bufio.install compress/flate.install hash/crc32.install hash.install io.install os.install compress/gzip.install: bufio.install compress/flate.install hash.install hash/crc32.install io.install os.install
compress/zlib.install: bufio.install compress/flate.install hash/adler32.install hash.install io.install os.install compress/zlib.install: bufio.install compress/flate.install hash.install hash/adler32.install io.install os.install
container/heap.install: sort.install container/heap.install: sort.install
container/list.install: container/list.install:
container/ring.install: container/ring.install:
...@@ -26,17 +26,16 @@ ebnf.install: container/vector.install go/scanner.install go/token.install os.in ...@@ -26,17 +26,16 @@ ebnf.install: container/vector.install go/scanner.install go/token.install os.in
encoding/ascii85.install: bytes.install io.install os.install strconv.install encoding/ascii85.install: bytes.install io.install os.install strconv.install
encoding/base64.install: bytes.install io.install os.install strconv.install encoding/base64.install: bytes.install io.install os.install strconv.install
encoding/binary.install: io.install math.install os.install reflect.install encoding/binary.install: io.install math.install os.install reflect.install
encoding/hex.install: os.install strconv.install strings.install
encoding/git85.install: bytes.install io.install os.install strconv.install encoding/git85.install: bytes.install io.install os.install strconv.install
encoding/pem.install: bytes.install encoding/base64.install strings.install encoding/pem.install: bytes.install encoding/base64.install strings.install
exec.install: os.install strings.install exec.install: os.install strings.install
exp/datafmt.install: bytes.install container/vector.install fmt.install go/scanner.install go/token.install io.install os.install reflect.install runtime.install strconv.install strings.install exp/datafmt.install: bytes.install container/vector.install fmt.install go/scanner.install go/token.install io.install os.install reflect.install runtime.install strconv.install strings.install
exp/eval.install: bignum.install fmt.install go/ast.install go/parser.install go/scanner.install go/token.install log.install os.install reflect.install runtime.install sort.install strconv.install strings.install exp/eval.install: bignum.install fmt.install go/ast.install go/parser.install go/scanner.install go/token.install log.install os.install reflect.install runtime.install strconv.install strings.install
exp/iterable.install: container/vector.install exp/iterable.install: container/vector.install
expvar.install: bytes.install fmt.install http.install log.install strconv.install sync.install expvar.install: bytes.install fmt.install http.install log.install strconv.install sync.install
flag.install: fmt.install os.install strconv.install flag.install: fmt.install os.install strconv.install
fmt.install: io.install os.install reflect.install strconv.install utf8.install fmt.install: io.install os.install reflect.install strconv.install utf8.install
go/ast.install: fmt.install go/token.install unicode.install utf8.install go/ast.install: go/token.install unicode.install utf8.install
go/doc.install: container/vector.install go/ast.install go/token.install io.install regexp.install sort.install strings.install template.install go/doc.install: container/vector.install go/ast.install go/token.install io.install regexp.install sort.install strings.install template.install
go/parser.install: bytes.install container/vector.install fmt.install go/ast.install go/scanner.install go/token.install io.install os.install path.install strings.install go/parser.install: bytes.install container/vector.install fmt.install go/ast.install go/scanner.install go/token.install io.install os.install path.install strings.install
go/printer.install: bytes.install container/vector.install fmt.install go/ast.install go/token.install io.install os.install reflect.install runtime.install strings.install tabwriter.install go/printer.install: bytes.install container/vector.install fmt.install go/ast.install go/token.install io.install os.install reflect.install runtime.install strings.install tabwriter.install
...@@ -48,7 +47,7 @@ hash/adler32.install: hash.install os.install ...@@ -48,7 +47,7 @@ hash/adler32.install: hash.install os.install
hash/crc32.install: hash.install os.install hash/crc32.install: hash.install os.install
http.install: bufio.install bytes.install container/vector.install fmt.install io.install log.install net.install os.install path.install strconv.install strings.install utf8.install http.install: bufio.install bytes.install container/vector.install fmt.install io.install log.install net.install os.install path.install strconv.install strings.install utf8.install
image.install: image.install:
image/png.install: bufio.install compress/zlib.install hash/crc32.install hash.install image.install io.install os.install strconv.install image/png.install: bufio.install compress/zlib.install hash.install hash/crc32.install image.install io.install os.install strconv.install
io.install: bytes.install os.install sort.install strings.install sync.install io.install: bytes.install os.install sort.install strings.install sync.install
json.install: bytes.install container/vector.install fmt.install math.install reflect.install strconv.install strings.install utf8.install json.install: bytes.install container/vector.install fmt.install math.install reflect.install strconv.install strings.install utf8.install
log.install: fmt.install io.install os.install runtime.install time.install log.install: fmt.install io.install os.install runtime.install time.install
...@@ -72,6 +71,7 @@ tabwriter.install: bytes.install container/vector.install io.install os.install ...@@ -72,6 +71,7 @@ tabwriter.install: bytes.install container/vector.install io.install os.install
template.install: bytes.install container/vector.install fmt.install io.install os.install reflect.install runtime.install strings.install template.install: bytes.install container/vector.install fmt.install io.install os.install reflect.install runtime.install strings.install
testing.install: flag.install fmt.install os.install runtime.install utf8.install testing.install: flag.install fmt.install os.install runtime.install utf8.install
testing/iotest.install: bytes.install io.install log.install os.install testing/iotest.install: bytes.install io.install log.install os.install
testing/quickcheck.install: flag.install rand.install reflect.install testing.install utf8.install
time.install: io.install once.install os.install syscall.install time.install: io.install once.install os.install syscall.install
unicode.install: unicode.install:
utf8.install: unicode.install utf8.install: unicode.install
......
...@@ -41,7 +41,6 @@ DIRS=\ ...@@ -41,7 +41,6 @@ DIRS=\
encoding/base64\ encoding/base64\
encoding/binary\ encoding/binary\
encoding/git85\ encoding/git85\
encoding/hex\
encoding/pem\ encoding/pem\
exec\ exec\
exp/datafmt\ exp/datafmt\
...@@ -86,6 +85,7 @@ DIRS=\ ...@@ -86,6 +85,7 @@ DIRS=\
template\ template\
testing\ testing\
testing/iotest\ testing/iotest\
testing/quickcheck\
time\ time\
unicode\ unicode\
utf8\ utf8\
......
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include $(GOROOT)/src/Make.$(GOARCH)
TARG=testing/quick
GOFILES=\
quick.go\
include $(GOROOT)/src/Make.pkg
This diff is collapsed.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package quick
import (
"rand";
"reflect";
"testing";
"os";
)
func fBool(a bool) bool {
return a;
}
func fFloat32(a float32) float32 {
return a;
}
func fFloat64(a float64) float64 {
return a;
}
func fFloat(a float) float {
return a;
}
func fInt16(a int16) int16 {
return a;
}
func fInt32(a int32) int32 {
return a;
}
func fInt64(a int64) int64 {
return a;
}
func fInt8(a int8) int8 {
return a;
}
func fInt(a int) int {
return a;
}
func fUInt8(a uint8) uint8 {
return a;
}
func fMap(a map[int]int) map[int]int {
return a;
}
func fSlice(a []byte) []byte {
return a;
}
func fString(a string) string {
return a;
}
type TestStruct struct {
A int;
B string;
}
func fStruct(a TestStruct) TestStruct {
return a;
}
func fUint16(a uint16) uint16 {
return a;
}
func fUint32(a uint32) uint32 {
return a;
}
func fUint64(a uint64) uint64 {
return a;
}
func fUint8(a uint8) uint8 {
return a;
}
func fUint(a uint) uint {
return a;
}
func fUintptr(a uintptr) uintptr {
return a;
}
func fIntptr(a *int) *int {
b := *a;
return &b;
}
func reportError(property string, err os.Error, t *testing.T) {
if err != nil {
t.Errorf("%s: %s", property, err);
}
}
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("fInt16", CheckEqual(fInt16, fInt16, nil), t);
reportError("fInt32", CheckEqual(fInt32, fInt32, nil), t);
reportError("fInt64", CheckEqual(fInt64, fInt64, nil), t);
reportError("fInt8", CheckEqual(fInt8, fInt8, nil), t);
reportError("fInt", CheckEqual(fInt, fInt, nil), t);
reportError("fUInt8", CheckEqual(fUInt8, fUInt8, nil), t);
reportError("fInt32", CheckEqual(fInt32, fInt32, nil), t);
reportError("fMap", CheckEqual(fMap, fMap, nil), t);
reportError("fSlice", CheckEqual(fSlice, fSlice, nil), t);
reportError("fString", CheckEqual(fString, fString, nil), t);
reportError("fStruct", CheckEqual(fStruct, fStruct, nil), t);
reportError("fUint16", CheckEqual(fUint16, fUint16, nil), t);
reportError("fUint32", CheckEqual(fUint32, fUint32, nil), t);
reportError("fUint64", CheckEqual(fUint64, fUint64, nil), t);
reportError("fUint8", CheckEqual(fUint8, fUint8, nil), t);
reportError("fUint", CheckEqual(fUint, fUint, nil), t);
reportError("fUintptr", CheckEqual(fUintptr, fUintptr, nil), t);
reportError("fIntptr", CheckEqual(fIntptr, fIntptr, nil), t);
}
// This tests that ArbitraryValue is working by checking that all the arbitrary
// values of type MyStruct have x = 42.
type myStruct struct {
x int;
}
func (m myStruct) Generate(r *rand.Rand, _ int) reflect.Value {
return reflect.NewValue(myStruct{x: 42});
}
func myStructProperty(in myStruct) bool {
return in.x == 42;
}
func TestCheckProperty(t *testing.T) {
reportError("myStructProperty", Check(myStructProperty, nil), t);
}
func TestFailure(t *testing.T) {
f := func(x int) bool { return false };
err := Check(f, nil);
if err == nil {
t.Errorf("Check didn't return an error");
}
if _, ok := err.(*CheckError); !ok {
t.Errorf("Error was not a CheckError: %s", err);
}
err = CheckEqual(fUint, fUint32, nil);
if err == nil {
t.Errorf("#1 CheckEqual didn't return an error");
}
if _, ok := err.(SetupError); !ok {
t.Errorf("#1 Error was not a SetupError: %s", err);
}
err = CheckEqual(func(x, y int) {}, func(x int) {}, nil);
if err == nil {
t.Errorf("#2 CheckEqual didn't return an error");
}
if _, ok := err.(SetupError); !ok {
t.Errorf("#2 Error was not a SetupError: %s", err);
}
err = CheckEqual(func(x int) int { return 0 }, func(x int) int32 { return 0 }, nil);
if err == nil {
t.Errorf("#3 CheckEqual didn't return an error");
}
if _, ok := err.(SetupError); !ok {
t.Errorf("#3 Error was not a SetupError: %s", err);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment