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


Golang quick.CheckEqual函数代码示例

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


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

示例1: TestMarshalUnmarshalArbitrary

func TestMarshalUnmarshalArbitrary(t *testing.T) {
	f := func(arb Arbitrary) interface{} { a, _ := standardize(arb.Value); return a }
	g := func(arb Arbitrary) interface{} {
		data, err := Marshal(arb.Value, XMLFormat)
		if err != nil {
			t.Error(err)
			return nil
		}
		var result interface{}
		format, err := Unmarshal(data, &result)
		if err != nil {
			t.Error(err)
			return nil
		}
		if format != XMLFormat {
			t.Error(err)
			return nil
		}
		a, _ := standardize(result)
		return a
	}
	if err := quick.CheckEqual(f, g, nil); err != nil {
		out1 := err.(*quick.CheckEqualError).Out1[0]
		out2 := err.(*quick.CheckEqualError).Out2[0]
		findDifferences(t, out1, out2)
		t.Error(err)
	}
}
开发者ID:kballard,项目名称:go-osx-plist,代码行数:28,代码来源:unmarshal_test.go

示例2: TestXXD

func TestXXD(t *testing.T) {
	if *xxdFile == "" {
		t.Skip("-xxdFile argument not given")
	}
	data, err := ioutil.ReadFile(*xxdFile)
	if err != nil {
		t.Fatal(err)
	}
	test := func(fn func(r io.Reader, w io.Writer, s string) error) func(n uint64) []string {
		return func(n uint64) []string {
			size := n % uint64(len(data))
			fmt.Printf("%d\n", size)
			var out bytes.Buffer
			if err := fn(&pathologicalReader{data[0:size]}, &out, ""); err != nil {
				return []string{err.Error()}
			}
			return strings.Split(out.String(), "\n")
		}
	}
	if err := quick.CheckEqual(test(xxd), test(xxdNative), nil); err != nil {
		cErr := err.(*quick.CheckEqualError)
		size := cErr.In[0].(uint64) % uint64(len(data))
		for i := range cErr.Out1[0].([]string) {
			got := cErr.Out1[0].([]string)[i]
			want := cErr.Out2[0].([]string)[i]
			if got != want {
				t.Errorf("size: %d\n\ngot : %s\nwant: %s\n", size, got, want)
				break
			}
		}
	}
}
开发者ID:HarryBird,项目名称:go-coreutils,代码行数:32,代码来源:xxd_test.go

示例3: TestQuickPythonEncodeBits

func TestQuickPythonEncodeBits(t *testing.T) {
	if !*python {
		t.Skip("Skipping, use -python to enable")
	}
	us := func(orig []byte, partial uint) (string, error) {
		bits := calcBits(orig, partial)
		encoded := zbase32.EncodeBitsToString(orig, bits)
		return encoded, nil
	}
	them := func(orig []byte, partial uint) (string, error) {
		// the python library raises IndexError on zero-length input
		if len(orig) == 0 {
			return "", nil
		}
		bits := calcBits(orig, partial)
		cmd := exec.Command("python", "-c", `
import sys, zbase32
orig = sys.stdin.read()
bits = int(sys.argv[1])
sys.stdout.write(zbase32.b2a_l(orig, bits))
`,
			strconv.Itoa(bits),
		)
		cmd.Stdin = bytes.NewReader(orig)
		cmd.Stderr = os.Stderr
		output, err := cmd.Output()
		if err != nil {
			return "", fmt.Errorf("cannot run python: %v", err)
		}
		return string(output), nil
	}
	if err := quick.CheckEqual(us, them, nil); err != nil {
		t.Fatal(err)
	}
}
开发者ID:nathansgreen,项目名称:zbase32,代码行数:35,代码来源:quick_test.go

示例4: TestCompareRead

func TestCompareRead(t *testing.T) {
	r := NewRandReader(42)
	buf := make([]byte, 10*1024*1024)
	r.Read(buf)

	blob := emptyBlob(t, &mock.InMemory{})
	blob.WriteAt(buf, 0)

	got := func(p []byte, off int64) (int, error) {
		if off < 0 {
			off = -off
		}
		return blob.ReadAt(p, off)
	}
	rat := bytes.NewReader(buf)
	exp := func(p []byte, off int64) (int, error) {
		if off < 0 {
			off = -off
		}
		return rat.ReadAt(p, off)
	}

	config := quick.Config{
		MaxCountScale: 100.0,
	}
	if err := quick.CheckEqual(got, exp, &config); err != nil {
		t.Error(err)
	}
}
开发者ID:som-snytt,项目名称:bazil,代码行数:29,代码来源:quickblobs_test.go

示例5: TestPackageMethods

func TestPackageMethods(t *T) {
	pkg := func(a, b, c, d, e, f string) string {
		buf := setupLogger()
		defer resetLogger()

		Println(a, b, c, d, e, f)
		Print(a, b, c, d, e, f)
		Printf(a, b, c, d, e, f)
		return buf.String()
	}

	dft := func(a, b, c, d, e, f string) string {
		buf := setupLogger()
		defer resetLogger()

		Default.Println(a, b, c, d, e, f)
		Default.Print(a, b, c, d, e, f)
		Default.Printf(a, b, c, d, e, f)
		return buf.String()
	}

	if err := quick.CheckEqual(pkg, dft, nil); err != nil {
		t.Error(err)
	}
}
开发者ID:cookieo9,项目名称:go-misc,代码行数:25,代码来源:debug_test.go

示例6: TestQuickPythonDecodeBytes

func TestQuickPythonDecodeBytes(t *testing.T) {
	if !*python {
		t.Skip("Skipping, use -python to enable")
	}
	us := func(orig []byte) ([]byte, error) {
		encoded := zbase32.EncodeToString(orig)
		return zbase32.DecodeString(encoded)
	}
	them := func(orig []byte) ([]byte, error) {
		// the python library raises IndexError on zero-length input
		if len(orig) == 0 {
			return []byte{}, nil
		}
		encoded := zbase32.EncodeToString(orig)

		cmd := exec.Command("python", "-c", `
import sys, zbase32
enc = sys.stdin.read()
sys.stdout.write(zbase32.a2b(enc))
`)
		cmd.Stdin = strings.NewReader(encoded)
		cmd.Stderr = os.Stderr
		output, err := cmd.Output()
		if err != nil {
			return nil, fmt.Errorf("cannot run python: %v", err)
		}
		return output, nil
	}
	if err := quick.CheckEqual(us, them, nil); err != nil {
		t.Fatal(err)
	}
}
开发者ID:nathansgreen,项目名称:zbase32,代码行数:32,代码来源:quick_test.go

示例7: TestSumBytes

func TestSumBytes(t *testing.T) {
	config := &quick.Config{MaxCount: 1 << 10}
	fast := func(x TestSlice) uint64 { return FastSumUint8(x) }
	slow := func(x TestSlice) uint64 { return SumUint8(x) }
	if err := quick.CheckEqual(fast, slow, config); err != nil {
		t.Error(err)
	}
}
开发者ID:pietergvw,项目名称:superfastmatch,代码行数:8,代码来源:sum_test.go

示例8: TestNodeID_logdist

func TestNodeID_logdist(t *testing.T) {
	logdistBig := func(a, b common.Hash) int {
		abig, bbig := new(big.Int).SetBytes(a[:]), new(big.Int).SetBytes(b[:])
		return new(big.Int).Xor(abig, bbig).BitLen()
	}
	if err := quick.CheckEqual(logdist, logdistBig, quickcfg()); err != nil {
		t.Error(err)
	}
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:9,代码来源:node_test.go

示例9: TestForward

func TestForward(t *testing.T) {
	if err := quick.CheckEqual(func(a, b []byte) ([]byte, error) {
		diff := Diff(a, b, 0)
		return Forward(a, diff)
	}, func(a, b []byte) ([]byte, error) {
		return b, nil
	}, nil); err != nil {
		t.Error(err)
	}
}
开发者ID:babybee,项目名称:bindiff,代码行数:10,代码来源:diff_test.go

示例10: TestReverse

func TestReverse(t *testing.T) {
	if err := quick.CheckEqual(func(a, b []byte) ([]byte, error) {
		diff := Diff(a, b, 0)
		return Reverse(b, diff)
	}, func(a, b []byte) ([]byte, error) {
		return a, nil
	}, nil); err != nil {
		t.Error(err)
	}
}
开发者ID:babybee,项目名称:bindiff,代码行数:10,代码来源:diff_test.go

示例11: TestClientSeek

func TestClientSeek(t *testing.T) {
	sftp, cmd := testClient(t, READONLY, NO_DELAY)
	defer cmd.Wait()
	defer sftp.Close()

	fOS, err := ioutil.TempFile("", "seek-test")
	if err != nil {
		t.Fatal(err)
	}
	defer fOS.Close()

	fSFTP, err := sftp.Open(fOS.Name())
	if err != nil {
		t.Fatal(err)
	}
	defer fSFTP.Close()

	writeN(t, fOS, seekBytes)

	if err := quick.CheckEqual(
		func(s seek) (string, int64) { s.set(t, fOS); return readHash(t, fOS) },
		func(s seek) (string, int64) { s.set(t, fSFTP); return readHash(t, fSFTP) },
		nil,
	); err != nil {
		t.Errorf("Seek: expected equal absolute seeks: %v", err)
	}

	if err := quick.CheckEqual(
		func(s seek) (string, int64) { s.current(t, fOS); return readHash(t, fOS) },
		func(s seek) (string, int64) { s.current(t, fSFTP); return readHash(t, fSFTP) },
		nil,
	); err != nil {
		t.Errorf("Seek: expected equal seeks from middle: %v", err)
	}

	if err := quick.CheckEqual(
		func(s seek) (string, int64) { s.end(t, fOS); return readHash(t, fOS) },
		func(s seek) (string, int64) { s.end(t, fSFTP); return readHash(t, fSFTP) },
		nil,
	); err != nil {
		t.Errorf("Seek: expected equal seeks from end: %v", err)
	}
}
开发者ID:marete,项目名称:restic,代码行数:43,代码来源:client_integration_test.go

示例12: TestNodeID_distcmp

func TestNodeID_distcmp(t *testing.T) {
	distcmpBig := func(target, a, b common.Hash) int {
		tbig := new(big.Int).SetBytes(target[:])
		abig := new(big.Int).SetBytes(a[:])
		bbig := new(big.Int).SetBytes(b[:])
		return new(big.Int).Xor(tbig, abig).Cmp(new(big.Int).Xor(tbig, bbig))
	}
	if err := quick.CheckEqual(distcmp, distcmpBig, quickcfg()); err != nil {
		t.Error(err)
	}
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:11,代码来源:node_test.go

示例13: TestConstantTimeByteEq

func TestConstantTimeByteEq(t *testing.T) {
	for i, test := range testConstandTimeByteEqData {
		if r := ConstantTimeByteEq(test.a, test.b); r != test.out {
			t.Errorf("#%d bad result (got %x, want %x)", i, r, test.out)
		}
	}
	err := quick.CheckEqual(ConstantTimeByteEq, byteEq, nil)
	if err != nil {
		t.Error(err)
	}
}
开发者ID:Greentor,项目名称:go,代码行数:11,代码来源:constant_time_test.go

示例14: TestNewEscaper

func TestNewEscaper(t *testing.T) {
	of := func(in chars) string {
		return oldunescape(string(in))
	}
	nf := func(in chars) string {
		return unescape(string(in))
	}
	if err := quick.CheckEqual(of, nf, nil); err != nil {
		t.Errorf("quickcheck failure: %v", err)
	}
}
开发者ID:dustin,项目名称:go-jsonpointer,代码行数:11,代码来源:bytes_test.go

示例15: TestCFNumber_Float64

func TestCFNumber_Float64(t *testing.T) {
	f := func(f float64) float64 { return f }
	g := func(f float64) float64 {
		cfNum := convertFloat64ToCFNumber(f)
		if cfNum == nil {
			t.Fatal("CFNumberRef is NULL (%#v)", f)
		}
		defer cfRelease(cfTypeRef(cfNum))
		return convertCFNumberToFloat64(cfNum)
	}
	if err := quick.CheckEqual(f, g, nil); err != nil {
		t.Error(err)
	}
}
开发者ID:kballard,项目名称:go-osx-plist,代码行数:14,代码来源:convert_test.go


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