當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。