当前位置: 首页>>代码示例>>Golang>>正文


Golang quick.Check函数代码示例

本文整理汇总了Golang中testing/quick.Check函数的典型用法代码示例。如果您正苦于以下问题:Golang Check函数的具体用法?Golang Check怎么用?Golang Check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestFu

// Its a hack to use the testing/quick functions to load up some
// test data.  And that is it.
//
// NOTE:
// TestFu sets up the test data and it is expected to be in
// 0<whatever>_test.go.  So don't move it from 0_test.go!
func TestFu(t *testing.T) {

	config := &quick.Config{}
	config.MaxCount = 100

	// collect random k/vs
	testdata[_testdata_keys] = make([]string, 0)
	testdata[_testdata_kv] = make(map[string][]byte)
	setup_kv := func(k string, v []byte) bool {
		dataset := testdata[_testdata_kv].(map[string][]byte)
		dataset[k] = v
		keyset := testdata[_testdata_keys].([]string)
		testdata[_testdata_keys] = append(keyset, k)
		return true // always
	}
	quick.Check(setup_kv, config)

	// collect random counter
	testdata[_testdata_counters] = make(map[string]int64)
	setup_counters := func(k string, v int64) bool {
		dataset := testdata[_testdata_counters].(map[string]int64)
		dataset[k] = v
		return true // always
	}
	quick.Check(setup_counters, config)

	// collect random numbers
	testdata[_testdata_nums] = make([]int64, 0)
	setup_nums := func(v int64) bool {
		dataset := testdata[_testdata_nums].([]int64)
		dataset = append(dataset, v)
		return true // always
	}
	quick.Check(setup_nums, config)
}
开发者ID:aaudis,项目名称:GoRedisSession,代码行数:41,代码来源:0data_test.go

示例2: TestFormatAndParse

func TestFormatAndParse(t *testing.T) {
	const fmt = "Mon MST " + RFC3339 // all fields
	f := func(sec int64) bool {
		t1 := SecondsToLocalTime(sec)
		if t1.Year < 1000 || t1.Year > 9999 {
			// not required to work
			return true
		}
		t2, err := Parse(fmt, t1.Format(fmt))
		if err != nil {
			t.Errorf("error: %s", err)
			return false
		}
		if !same(t1, t2) {
			t.Errorf("different: %q %q", t1, t2)
			return false
		}
		return true
	}
	f32 := func(sec int32) bool { return f(int64(sec)) }
	cfg := &quick.Config{MaxCount: 10000}

	// Try a reasonable date first, then the huge ones.
	if err := quick.Check(f32, cfg); err != nil {
		t.Fatal(err)
	}
	if err := quick.Check(f, cfg); err != nil {
		t.Fatal(err)
	}
}
开发者ID:ssrl,项目名称:go,代码行数:30,代码来源:time_test.go

示例3: TestFormatAndParse

func TestFormatAndParse(t *testing.T) {
	const fmt = "Mon MST " + RFC3339 // all fields
	f := func(sec int64) bool {
		t1 := Unix(sec, 0)
		if t1.Year() < 1000 || t1.Year() > 9999 {
			// not required to work
			return true
		}
		t2, err := Parse(fmt, t1.Format(fmt))
		if err != nil {
			t.Errorf("error: %s", err)
			return false
		}
		if t1.Unix() != t2.Unix() || t1.Nanosecond() != t2.Nanosecond() {
			t.Errorf("FormatAndParse %d: %q(%d) %q(%d)", sec, t1, t1.Unix(), t2, t2.Unix())
			return false
		}
		return true
	}
	f32 := func(sec int32) bool { return f(int64(sec)) }
	cfg := &quick.Config{MaxCount: 10000}

	// Try a reasonable date first, then the huge ones.
	if err := quick.Check(f32, cfg); err != nil {
		t.Fatal(err)
	}
	if err := quick.Check(f, cfg); err != nil {
		t.Fatal(err)
	}
}
开发者ID:h8liu,项目名称:golang,代码行数:30,代码来源:format_test.go

示例4: ReadEmptyTests

func ReadEmptyTests(p MetricPersistence, t test.Tester) {
	hasLabelPair := func(x int) (success bool) {
		name := model.LabelName(string(x))
		value := model.LabelValue(string(x))

		labelSet := model.LabelSet{
			name: value,
		}

		fingerprints, err := p.GetFingerprintsForLabelSet(labelSet)
		if err != nil {
			t.Error(err)
			return
		}

		success = len(fingerprints) == 0
		if !success {
			t.Errorf("unexpected fingerprint length %d, got %d", 0, len(fingerprints))
		}

		return
	}

	err := quick.Check(hasLabelPair, nil)
	if err != nil {
		t.Error(err)
		return
	}

	hasLabelName := func(x int) (success bool) {
		labelName := model.LabelName(string(x))

		fingerprints, err := p.GetFingerprintsForLabelName(labelName)
		if err != nil {
			t.Error(err)
			return
		}

		success = len(fingerprints) == 0
		if !success {
			t.Errorf("unexpected fingerprint length %d, got %d", 0, len(fingerprints))
		}

		return
	}

	err = quick.Check(hasLabelName, nil)
	if err != nil {
		t.Error(err)
		return
	}
}
开发者ID:bernerdschaefer,项目名称:prometheus,代码行数:52,代码来源:stochastic_test.go

示例5: TestSecondsToUTCAndBack

func TestSecondsToUTCAndBack(t *testing.T) {
	f := func(sec int64) bool { return Unix(sec, 0).UTC().Unix() == sec }
	f32 := func(sec int32) bool { return f(int64(sec)) }
	cfg := &quick.Config{MaxCount: 10000}

	// Try a reasonable date first, then the huge ones.
	if err := quick.Check(f32, cfg); err != nil {
		t.Fatal(err)
	}
	if err := quick.Check(f, cfg); err != nil {
		t.Fatal(err)
	}
}
开发者ID:Ericean,项目名称:go,代码行数:13,代码来源:time_test.go

示例6: TestNanosecondsToUTCAndBack

func TestNanosecondsToUTCAndBack(t *testing.T) {
	f := func(nsec int64) bool { return NanosecondsToUTC(nsec).Nanoseconds() == nsec }
	f32 := func(nsec int32) bool { return f(int64(nsec)) }
	cfg := &quick.Config{MaxCount: 10000}

	// Try a small date first, then the large ones. (The span is only a few hundred years
	// for nanoseconds in an int64.)
	if err := quick.Check(f32, cfg); err != nil {
		t.Fatal(err)
	}
	if err := quick.Check(f, cfg); err != nil {
		t.Fatal(err)
	}
}
开发者ID:WXB506,项目名称:golang,代码行数:14,代码来源:time_test.go

示例7: main

func main() {
	intf := func(x int) bool {
		fmt.Println(x)
		return true
	}

	quick.Check(intf, nil)

	personf := func(p *Person) bool {
		fmt.Printf("%+v\n", p)
		return true
	}
	quick.Check(personf, nil)
}
开发者ID:sunfmin,项目名称:learn_go_the_hard_way,代码行数:14,代码来源:testing_quick.go

示例8: ReadEmptyTests

func ReadEmptyTests(p metric.Persistence, t test.Tester) {
	hasLabelPair := func(x int) (success bool) {
		fingerprints, err := p.GetFingerprintsForLabelMatchers(metric.LabelMatchers{{
			Type:  metric.Equal,
			Name:  clientmodel.LabelName(string(x)),
			Value: clientmodel.LabelValue(string(x)),
		}})
		if err != nil {
			t.Error(err)
			return
		}

		success = len(fingerprints) == 0
		if !success {
			t.Errorf("unexpected fingerprint length %d, got %d", 0, len(fingerprints))
		}

		return
	}

	err := quick.Check(hasLabelPair, nil)
	if err != nil {
		t.Error(err)
		return
	}

	hasLabelName := func(x int) (success bool) {
		labelName := clientmodel.LabelName(string(x))

		values, err := p.GetLabelValuesForLabelName(labelName)
		if err != nil {
			t.Error(err)
			return
		}

		success = len(values) == 0
		if !success {
			t.Errorf("unexpected values length %d, got %d", 0, len(values))
		}

		return
	}

	err = quick.Check(hasLabelName, nil)
	if err != nil {
		t.Error(err)
		return
	}
}
开发者ID:pjjw,项目名称:prometheus,代码行数:49,代码来源:stochastic_test.go

示例9: TestQuickGranularStorage

func TestQuickGranularStorage(t *testing.T) {
	gs := newGranularStorage(8, adapters.NewMemoryStorage(make([]byte, 0, 4096)), adapters.NewMemoryStorage(make([]byte, 0, 4096)))
	//add
	if err := quick.Check(func(b []byte) bool {
		i, err := gs.add(b)
		if err != nil || i != gs.len()-1 {
			return false
		}
		if i > 2 {
			err = gs.set(i-1, []byte{})
			if err != nil {
				return false
			}
		}
		if i > 5 {
			err = gs.del(i - 3)
			if err != nil {
				return false
			}
		}
		return true
	}, nil); err != nil {
		t.Error(err)
	}
}
开发者ID:mrkovec,项目名称:str,代码行数:25,代码来源:granularStorage_test.go

示例10: TestDomainQuick

func TestDomainQuick(t *testing.T) {
	r := rand.New(rand.NewSource(0))
	f := func(l int) bool {
		db := GenerateDomain(r, l)
		ds, _, err := UnpackDomainName(db, 0)
		if err != nil {
			panic(err)
		}
		buf := make([]byte, 255)
		off, err := PackDomainName(ds, buf, 0, nil, false)
		if err != nil {
			t.Logf("error packing domain: %s", err.Error())
			t.Logf(" bytes: %v\n", db)
			t.Logf("string: %v\n", ds)
			return false
		}
		if !bytes.Equal(db, buf[:off]) {
			t.Logf("repacked domain doesn't match original:")
			t.Logf("src bytes: %v", db)
			t.Logf("   string: %v", ds)
			t.Logf("out bytes: %v", buf[:off])
			return false
		}
		return true
	}
	if err := quick.Check(f, nil); err != nil {
		t.Error(err)
	}
}
开发者ID:abh,项目名称:dns,代码行数:29,代码来源:parse_test.go

示例11: TestFuzz

func TestFuzz(t *testing.T) {
	rnd := rand.New(rand.NewSource(42))
	check := func() bool {
		messages := rndMessages(rnd)
		var buf bytes.Buffer
		var written int
		for i, msg := range messages {
			n, err := WriteDelimited(&buf, msg)
			if err != nil {
				t.Fatalf("WriteDelimited(buf, %v[%d]) = ?, %v; wanted ?, nil", messages, i, err)
			}
			written += n
		}
		var read int
		for i, msg := range messages {
			out := Clone(msg)
			out.Reset()
			n, _ := ReadDelimited(&buf, out)
			read += n
			if !Equal(out, msg) {
				t.Fatalf("out = %v; want %v[%d] = %#v", out, messages, i, msg)
			}
		}
		if read != written {
			t.Fatalf("%v read = %d; want %d", messages, read, written)
		}
		return true
	}
	if err := quick.Check(check, nil); err != nil {
		t.Fatal(err)
	}
}
开发者ID:ikatson,项目名称:etcd,代码行数:32,代码来源:all_test.go

示例12: Test_SessionCookieStore

func Test_SessionCookieStore(t *testing.T) {
	if err := quick.Check(func(k, v string) bool {
		expected := make(kocha.Session)
		expected[k] = v
		store := kocha.NewTestSessionCookieStore()
		r, err := store.Save(expected)
		if err != nil {
			t.Fatal(err)
		}
		actual, err := store.Load(r)
		if err != nil {
			t.Fatal(err)
		}
		return reflect.DeepEqual(actual, expected)
	}, nil); err != nil {
		t.Error(err)
	}

	func() {
		store := kocha.NewTestSessionCookieStore()
		key := "invalid"
		_, err := store.Load(key)
		actual := err
		expect := fmt.Errorf("kocha: session cookie value too short")
		if !reflect.DeepEqual(actual, expect) {
			t.Errorf(`SessionCookieStore.Load(%#v) => _, %#v; want %#v`, key, actual, expect)
		}
	}()
}
开发者ID:woremacx,项目名称:kocha,代码行数:29,代码来源:session_test.go

示例13: TestCFString_Invalid

func TestCFString_Invalid(t *testing.T) {
	// go ahead and generate random strings and see if we actually get objects back.
	// This is testing the unicode replacement functionality.
	// Just to be safe in case testing/quick ever fixes their string generation to
	// only generate valid strings, lets generate []bytes instead and then convert that.
	f := func(bytes []byte) bool {
		s := string(bytes)
		cfStr := convertStringToCFString(s)
		defer cfRelease(cfTypeRef(cfStr))
		return cfStr != nil
	}
	if err := quick.Check(f, nil); err != nil {
		t.Error(err)
	}

	// Test some manually-crafted strings
	g := func(input, expected string) {
		cfStr := convertStringToCFString(input)
		defer cfRelease(cfTypeRef(cfStr))
		if cfStr == nil {
			t.Errorf("failed on input %#v", input)
			return
		}
		output := convertCFStringToString(cfStr)
		if output != expected {
			t.Errorf("failed on input: %#v. Output: %#v. Expected: %#v", input, output, expected)
		}
	}
	g("hello world", "hello world")
	g("hello\x00world", "hello\x00world")
	g("hello\uFFFDworld", "hello\uFFFDworld")
	g("hello\uFEFFworld\x00", "hello\uFEFFworld\x00")
	g("hello\x80world", "hello\uFFFDworld")
	g("hello\xFE\xFFworld", "hello\uFFFD\uFFFDworld")
}
开发者ID:kballard,项目名称:go-osx-plist,代码行数:35,代码来源:convert_test.go

示例14: Test_BooleanEncoder_Quick

func Test_BooleanEncoder_Quick(t *testing.T) {
	if err := quick.Check(func(values []bool) bool {
		expected := values
		if values == nil {
			expected = []bool{}
		}
		// Write values to encoder.
		enc := tsm1.NewBooleanEncoder()
		for _, v := range values {
			enc.Write(v)
		}

		// Retrieve compressed bytes.
		buf, err := enc.Bytes()
		if err != nil {
			t.Fatal(err)
		}

		// Read values out of decoder.
		got := make([]bool, 0, len(values))
		dec := tsm1.NewBooleanDecoder(buf)
		for dec.Next() {
			got = append(got, dec.Read())
		}

		// Verify that input and output values match.
		if !reflect.DeepEqual(expected, got) {
			t.Fatalf("mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", expected, got)
		}

		return true
	}, nil); err != nil {
		t.Fatal(err)
	}
}
开发者ID:skia-dev,项目名称:influxdb,代码行数:35,代码来源:bool_test.go

示例15: TestNewRank

func TestNewRank(t *testing.T) {
	err := quick.Check(func(r1, r2 Rank) bool {
		if len(r1) == 0 || len(r2) == 0 {
			return true
		}

		if r1.String() == r2.String() {
			return true
		}

		between, err := NewRank(r1, r2)
		if err != nil {
			t.Log(err)
			return false
		}

		if r1.String() > r2.String() {
			r1, r2 = r2, r1
		}

		return r1.String() < between.String() &&
			between.String() < r2.String()
	}, nil)
	if err != nil {
		t.Error(err)
	}
}
开发者ID:trythings,项目名称:trythings,代码行数:27,代码来源:rank_test.go


注:本文中的testing/quick.Check函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。