aboutsummaryrefslogtreecommitdiff
path: root/quick_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-02-01 09:42:11 -0800
committerBen Johnson <benbjohnson@yahoo.com>2014-02-01 09:42:11 -0800
commitb2a78a23644bf7cddb81059bd19176ebbe44710e (patch)
treed6aa197560053444d76dce1bd198a584c051c7b9 /quick_test.go
parentMerge pull request #4 from benbjohnson/api (diff)
parentAdd RWTransaction.Put(). (diff)
downloaddedo-b2a78a23644bf7cddb81059bd19176ebbe44710e.tar.gz
dedo-b2a78a23644bf7cddb81059bd19176ebbe44710e.tar.xz
Merge pull request #5 from benbjohnson/put
Add RWTransaction.Put().
Diffstat (limited to 'quick_test.go')
-rw-r--r--quick_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/quick_test.go b/quick_test.go
new file mode 100644
index 0000000..d85249d
--- /dev/null
+++ b/quick_test.go
@@ -0,0 +1,65 @@
+package bolt
+
+import (
+ "flag"
+ "math/rand"
+ "reflect"
+ "testing/quick"
+ "time"
+)
+
+// testing/quick defaults to 100 iterations and a random seed.
+// You can override these settings from the command line:
+//
+// -quickchecks The number of iterations to perform.
+// -quick.seed The seed to use for randomizing.
+// -quick.maxitems The maximum number of items to insert into a DB.
+// -quick.maxksize The maximum size of a key.
+// -quick.maxvsize The maximum size of a value.
+//
+
+var seed, testMaxItemCount, testMaxKeySize, testMaxValueSize int
+
+func init() {
+ flag.IntVar(&seed, "quick.seed", int(time.Now().UnixNano())%100000, "")
+ flag.IntVar(&testMaxItemCount, "quick.maxitems", 1024, "")
+ flag.IntVar(&testMaxKeySize, "quick.maxksize", 1024, "")
+ flag.IntVar(&testMaxValueSize, "quick.maxvsize", 1024, "")
+ warn("seed:", seed)
+}
+
+// qc creates a testing/quick configuration.
+func qc() *quick.Config {
+ return &quick.Config{Rand: rand.New(rand.NewSource(int64(seed)))}
+}
+
+type testKeyValuePairs []testKeyValuePair
+
+func (t testKeyValuePairs) Generate(rand *rand.Rand, size int) reflect.Value {
+ n := rand.Intn(testMaxItemCount-1) + 1
+ items := make(testKeyValuePairs, n)
+ for i := 0; i < n; i++ {
+ items[i].Generate(rand, size)
+ }
+ return reflect.ValueOf(items)
+}
+
+type testKeyValuePair struct {
+ Key []byte
+ Value []byte
+}
+
+func (t testKeyValuePair) Generate(rand *rand.Rand, size int) reflect.Value {
+ t.Key = randByteSlice(rand, 1, testMaxKeySize)
+ t.Value = randByteSlice(rand, 0, testMaxValueSize)
+ return reflect.ValueOf(t)
+}
+
+func randByteSlice(rand *rand.Rand, minSize, maxSize int) []byte {
+ n := rand.Intn(maxSize - minSize) + minSize
+ b := make([]byte, n)
+ for i := 0; i < n; i++ {
+ b[i] = byte(rand.Intn(255))
+ }
+ return b
+}