當前位置: 首頁>>代碼示例>>Golang>>正文


Golang assert.Equal函數代碼示例

本文整理匯總了Golang中github.com/tobinjt/assert.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Equal函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestSquareChain

func TestSquareChain(t *testing.T) {
	cache := make([]uint, squareChainCacheSize)
	cache[1] = 1
	cache[89] = 89
	assert.Equal(t, "squareChain(1)", uint(1), squareChain(1, cache))
	assert.Equal(t, "squareChain(89)", uint(89), squareChain(89, cache))
	assert.Equal(t, "squareChain(44)", uint(1), squareChain(44, cache))
	assert.Equal(t, "squareChain(85)", uint(89), squareChain(85, cache))
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:9,代碼來源:project-euler_test.go

示例2: TestFactorialBigIntCached

func TestFactorialBigIntCached(t *testing.T) {
	cache := []*big.Int{big.NewInt(1), big.NewInt(1), big.NewInt(2), big.NewInt(6), nil, nil}
	factorialBigIntCached(5, cache)
	assert.Equal(t, "factorialBigIntCached(5, cache)", int64(120), cache[5].Int64())
	p := cache[5]
	factorialBigIntCached(5, cache)
	assert.Equal(t, "do not overwrite", p, cache[5])
	if cache[4] != nil {
		t.Errorf("factorialBigIntCached(5, cache): cache[4]: got %v, want nil", cache[4])
	}
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:11,代碼來源:project-euler_test.go

示例3: TestNgons

func TestNgons(t *testing.T) {
	gon := NewNGon(3)
	gon.Set(0, []int{2, 5, 8})
	gon.Set(1, []int{1, 6, 7})
	gon.Set(2, []int{3, 4, 9})
	assert.Equal(t, "gon.Get()", []int{2, 9, 6}, gon.Get(0))
	assert.Equal(t, "gon.String()", "sum: 11: first: 1 1,6,4; 3,4,9; 2,9,6",
		gon.String())
	assert.Equal(t, "gon.Copy()", gon, gon.Copy())
	actualInt, err := gon.ToInt()
	assert.ErrIsNil(t, "gon.ToInt()", err)
	assert.Equal(t, "gon.ToInt()", int64(164349296), actualInt)
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:13,代碼來源:project-euler_test.go

示例4: TestNumPrimePartitions

func TestNumPrimePartitions(t *testing.T) {
	sieve := SieveOfEratosthenes(50)
	sopfCache := make(map[int]int)
	nppCache := make(map[int]int)
	assert.Equal(t, "NumPrimePartitions", 1,
		NumPrimePartitions(2, sieve, nppCache, sopfCache))
	assert.Equal(t, "NumPrimePartitions", 7,
		NumPrimePartitions(12, sieve, nppCache, sopfCache))
	assert.Equal(t, "NumPrimePartitions", 10,
		NumPrimePartitions(14, sieve, nppCache, sopfCache))
	assert.Equal(t, "NumPrimePartitions", 26,
		NumPrimePartitions(20, sieve, nppCache, sopfCache))
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:13,代碼來源:project-euler_test.go

示例5: TestTwoDPointHeap

func TestTwoDPointHeap(t *testing.T) {
	n1 := TwoDPoint{cost: 1}
	n2 := TwoDPoint{cost: 2}
	n3 := TwoDPoint{cost: 3}
	n4 := TwoDPoint{cost: 4}

	h := &TwoDPointHeap{n2, n4, n1}
	heap.Init(h)
	assert.Equal(t, "Expecting n1", n1, heap.Pop(h))
	heap.Push(h, n3)
	assert.Equal(t, "Expecting n2", n2, heap.Pop(h))
	assert.Equal(t, "Expecting n3", n3, heap.Pop(h))
	assert.Equal(t, "Expecting n4", n4, heap.Pop(h))
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:14,代碼來源:project-euler_test.go

示例6: TestSqrt

func TestSqrt(t *testing.T) {
	expected := []int{1, 4, 1, 4, 2, 1, 3, 5, 6, 2}
	assert.Equal(t, "SqrtPE80(2, 10)", expected, SqrtPE80(2, 10))
	expected = []int{5}
	assert.Equal(t, "SqrtPE80(25, 10)", expected, SqrtPE80(25, 10))
	expected = []int{3, 1}
	assert.Equal(t, "SqrtPE80(961, 10)", expected, SqrtPE80(961, 10))
	expected = []int{1, 4, 1, 4, 2, 1, 3, 5, 6, 2, 3, 7, 3, 0, 9, 5, 0, 4,
		8, 8, 0, 1, 6, 8, 8, 7, 2, 4, 2, 0, 9, 6, 9, 8, 0, 7, 8, 5, 6,
		9, 6, 7, 1, 8, 7, 5, 3, 7, 6, 9, 4, 8, 0, 7, 3, 1, 7, 6, 6, 7,
		9, 7, 3, 7, 9, 9, 0, 7, 3, 2, 4, 7, 8, 4, 6, 2, 1, 0, 7, 0, 3,
		8, 8, 5, 0, 3, 8, 7, 5, 3, 4, 3, 2, 7, 6, 4, 1, 5, 7, 2}
	assert.Equal(t, "SqrtPE80(2, 100)", expected, SqrtPE80(2, 100))
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:14,代碼來源:project-euler_test.go

示例7: TestRomanNumeralsToUint

func TestRomanNumeralsToUint(t *testing.T) {
	shouldAssert := []struct {
		input string
		msg   string
	}{
		{input: "", msg: "empty string is invalid"},
		{input: "JTXIV", msg: "unrecognised sequence: JTXIV"},
		{input: "XIJI", msg: "unrecognised sequence: JI"},
		{input: "DIXX", msg: "sequence \"X\" followed smaller sequence \"IX\""},
	}
	for _, test := range shouldAssert {
		func() {
			defer assert.Panics(t, "romanNumeralsToUint(\""+test.input+"\")",
				test.msg)
			_ = romanNumeralsToUint(test.input)
		}()
	}

	valid := []struct {
		input  string
		result uint
	}{
		{input: "III", result: 3},
		{input: "V", result: 5},
		{input: "X", result: 10},
		{input: "XIX", result: 19},
		{input: "LV", result: 55},
		{input: "DCLXVI", result: 666},
		{input: "MCMXCVII", result: 1997},
	}
	for _, test := range valid {
		result := romanNumeralsToUint(test.input)
		assert.Equal(t, "romanNumeralsToUint(\""+test.input+"\")", test.result, result)
	}
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:35,代碼來源:project-euler_test.go

示例8: TestGeneralisedpentagonalNumber

func TestGeneralisedpentagonalNumber(t *testing.T) {
	expected := []int{0, 1, 2, 5, 7, 12, 15, 22, 26, 35, 40}
	for number, result := range expected {
		assert.Equal(t, "generalisedPentagonalNumber", result,
			generalisedPentagonalNumber(number))
	}
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:7,代碼來源:project-euler_test.go

示例9: TestFillDiceRolls

func TestFillDiceRolls(t *testing.T) {
	faces, position, rollsLeft := int64(2), int64(0), int64(2)
	rolls := make([]int64, faces*rollsLeft*2)
	fillDiceRolls(rolls, faces, position, rollsLeft)

	expected := []int64{4, 0, 1, 2, 1, 2, 0, 2}
	assert.Equal(t, "fillDiceRolls", expected, rolls)
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:8,代碼來源:project-euler_test.go

示例10: TestReadLinesFromFile

func TestReadLinesFromFile(t *testing.T) {
	fh := bytes.NewBufferString("1\n2 3\n")
	expected := []string{"1", "2 3"}
	actual := readLinesFromFile(fh)
	assert.Equal(t, "readLinesFromFile bad result", expected, actual)

	fh2 := iotest.TimeoutReader(bytes.NewBufferString("1\n2 3\n"))
	defer assert.Panics(t, "readLinesFromFile() should panic on failure", "Reading lines failed")
	_ = readLinesFromFile(fh2)
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:10,代碼來源:project-euler_test.go

示例11: TestMakeChildren

func TestMakeChildren(t *testing.T) {
	parent := PythagoreanTriple{a: 3, b: 4, c: 5}
	expectedChildren := []PythagoreanTriple{
		PythagoreanTriple{a: 5, b: 12, c: 13},
		PythagoreanTriple{a: 21, b: 20, c: 29},
		PythagoreanTriple{a: 15, b: 8, c: 17},
	}
	children := parent.MakeChildren()
	assert.Equal(t, "MakeChildren", expectedChildren, children)
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:10,代碼來源:project-euler_test.go

示例12: TestNumIntegerPartitions2

func TestNumIntegerPartitions2(t *testing.T) {
	expected := []int64{1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101,
		135, 176, 231, 297, 385, 490, 627, 792, 1002, 1255, 1575, 1958,
		2436, 3010, 3718, 4565, 5604, 6842, 8349, 10143, 12310, 14883,
		17977, 21637, 26015, 31185, 37338, 44583, 53174, 63261, 75175,
		89134, 105558, 124754, 147273, 173525}
	for number, result := range expected {
		assert.Equal(t, "NumIntegerPartitions2", result,
			NumIntegerPartitions2(number).Int64())
	}
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:11,代碼來源:project-euler_test.go

示例13: TestNCRInt64

func TestNCRInt64(t *testing.T) {
	tests := []struct {
		n, r, e int64
	}{
		{1, 1, 1},
		{4, 2, 6},
		{7, 4, 35},
	}
	for _, test := range tests {
		assert.Equal(t, fmt.Sprintf("nCrInt64(%v)", test.n), test.e, nCrInt64(test.n, test.r))
	}
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:12,代碼來源:project-euler_test.go

示例14: TestPermuteKOfN

func TestPermuteKOfN(t *testing.T) {
	p := make([]bool, 4)
	for _, test := range [][]bool{
		{false, false, false, true},
		{false, false, true, false},
		{false, false, true, true},
		{false, true, false, false},
		{false, true, false, true},
		{false, true, true, false},
		{true, false, false, false},
		{true, false, false, true},
		{true, false, true, false},
		{true, true, false, false},
	} {
		r := PermuteUpToKOfN(p, 2)
		assert.Equal(t, "PermuteUpToKOfN", true, r)
		assert.Equal(t, "PermuteUpToKOfN", test, p)
	}
	r := PermuteUpToKOfN(p, 2)
	assert.Equal(t, "PermuteUpToKOfN", false, r)
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:21,代碼來源:project-euler_test.go

示例15: TestFactorialBigIntCompareImplementations

func TestFactorialBigIntCompareImplementations(t *testing.T) {
	size := 7
	cached := make([]*big.Int, size)
	uncached := make([]*big.Int, size)
	expected := make([]*big.Int, size)
	expected[0] = big.NewInt(1)
	expected[1] = big.NewInt(1)
	expected[2] = big.NewInt(2)
	expected[3] = big.NewInt(6)
	expected[4] = big.NewInt(24)
	expected[5] = big.NewInt(120)
	expected[6] = big.NewInt(720)

	for i := 0; i < size; i++ {
		uncached[i] = factorialBigInt(int64(i))
		factorialBigIntCached(int64(i), cached)
	}

	assert.Equal(t, "cached", expected, cached)
	assert.Equal(t, "uncached", expected, uncached)
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:21,代碼來源:project-euler_test.go


注:本文中的github.com/tobinjt/assert.Equal函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。