本文整理汇总了Golang中github.com/golangplus/testing/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSaveSnapshot
func TestSaveSnapshot(t *testing.T) {
const (
site = "TestUpdateReadDeletePackageHistory.com"
path = "gcse"
foundWay = "testing"
)
assert.NoError(t, UpdatePackageHistory(site, path, func(info *sppb.HistoryInfo) error {
assert.Equal(t, "info", info, &sppb.HistoryInfo{})
info.FoundWay = foundWay
return nil
}))
h, err := ReadPackageHistory(site, path)
assert.NoError(t, err)
assert.Equal(t, "h", h, &sppb.HistoryInfo{FoundWay: foundWay})
outPath := villa.Path(os.TempDir()).Join("TestSaveSnapshot").S()
assert.NoError(t, SaveSnapshot(outPath))
box := &bh.RefCountBox{
DataPath: func() string {
return outPath
},
}
h, err = ReadPackageHistoryOf(box, site, path)
assert.NoError(t, err)
assert.Equal(t, "h", h, &sppb.HistoryInfo{FoundWay: foundWay})
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:26,代码来源:history_test.go
示例2: TestIndex_DescNotIndexedBug
func TestIndex_DescNotIndexedBug(t *testing.T) {
const (
description = "description"
readme = "readme"
)
hits := []HitInfo{{
DocInfo: DocInfo{
Package: "github.com/daviddengcn/gcse",
Name: "gcse",
Description: description,
ReadmeData: readme,
},
}}
idxs := []int{0}
fullHitSaved := 0
ts := &index.TokenSetSearcher{}
assert.NoError(t, indexAndSaveHits(ts, hits, idxs, func(hit *HitInfo) error {
fullHitSaved++
assert.Equal(t, "Description", hit.Description, description)
assert.Equal(t, "Readme", hit.ReadmeData, readme)
return nil
}))
assert.Equal(t, "fullHitSaved", fullHitSaved, 1)
results, err := search(ts, IndexTextField, description)
assert.NoError(t, err)
assert.Equal(t, "results", results, hits)
results, err = search(ts, IndexTextField, readme)
assert.NoError(t, err)
assert.Equal(t, "results", results, hits)
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:31,代码来源:index_test.go
示例3: TestStrSet_nil
func TestStrSet_nil(t *testing.T) {
var s, ss StrSet
assert.Equal(t, "nil.In(david)", s.In("david"), false)
assert.Equal(t, "nil.Equals(nil)", s.Equals(ss), true)
assert.StringEqual(t, "nil.Elements()", s.Elements(), StringSlice{})
s.Delete("david")
}
开发者ID:postfix,项目名称:go-villa,代码行数:7,代码来源:strset_test.go
示例4: TestRefCountBox_UpdateView
func TestRefCountBox_UpdateView(t *testing.T) {
fn := path.Join(os.TempDir(), "TestRefCountBox_UpdateView.bolt")
assert.NoError(t, os.RemoveAll(fn))
b := RefCountBox{
DataPath: func() string { return fn },
}
k := bytes.Split([]byte("a.b"), []byte("."))
v := "hello"
assert.NoErrorOrDie(t, b.Update(func(tx Tx) error {
return tx.Put(k, []byte(v))
}))
assert.Equal(t, "b.count", b.count, 0)
assert.ValueShould(t, "b.db.DB", b.db.DB, b.db.DB == nil, "is not nil")
found := false
assert.NoErrorOrDie(t, b.View(func(tx Tx) error {
return tx.Value(k, func(bs bytesp.Slice) error {
found = true
assert.Equal(t, "bs", string(v), string(bs))
return nil
})
}))
assert.Equal(t, "b.count", b.count, 0)
assert.ValueShould(t, "b.db.DB", b.db.DB, b.db.DB == nil, "is not nil")
}
开发者ID:daviddengcn,项目名称:bolthelper,代码行数:26,代码来源:box_test.go
示例5: TestInc
func TestInc(t *testing.T) {
DataPath = "./tmp.bolt"
FlushPeriod = time.Second
err := os.RemoveAll(DataPath)
if err != nil && err != os.ErrNotExist {
assert.NoError(t, err)
return
}
now := time.Now()
Inc("abc")
Flush()
Process()
names, err := ReadNames()
assert.NoError(t, err)
assert.Equal(t, "names", names, []string{"abc"})
data, err := ReadDataOfName("daily", "abc")
assert.NoError(t, err)
assert.Equal(t, "data", data, []LabeledCounter{{
Counter{
Sum: 1,
Div: 1,
},
now.Format("2006-01-02"),
}})
}
开发者ID:daviddengcn,项目名称:go-easybi,代码行数:28,代码来源:bi_test.go
示例6: TestCheckPackageStatus
func TestCheckPackageStatus(t *testing.T) {
// No crawling info, new package
assert.Equal(t, "CheckPackageStatus", CheckPackageStatus(&stpb.PackageInfo{}, nil), OutOfDate)
pkgCrawlTime, _ := ptypes.TimestampProto(time.Now().Add(-5 * timep.Day))
newRepoInfoCrawlTime, _ := ptypes.TimestampProto(time.Now().Add(-3 * timep.Day))
newPkgUpdateTime, _ := ptypes.TimestampProto(time.Now().Add(-4 * timep.Day))
assert.Equal(t, "CheckPackageStatus", CheckPackageStatus(&stpb.PackageInfo{
CrawlingInfo: &sppb.CrawlingInfo{
CrawlingTime: pkgCrawlTime,
},
}, &sppb.RepoInfo{
CrawlingTime: newRepoInfoCrawlTime,
LastUpdated: newPkgUpdateTime,
}), OutOfDate)
newPkgUpdateTime, _ = ptypes.TimestampProto(time.Now().Add(-6 * timep.Day))
assert.Equal(t, "CheckPackageStatus", CheckPackageStatus(&stpb.PackageInfo{
CrawlingInfo: &sppb.CrawlingInfo{
CrawlingTime: pkgCrawlTime,
},
}, &sppb.RepoInfo{
CrawlingTime: newRepoInfoCrawlTime,
LastUpdated: newPkgUpdateTime,
}), UpToDate)
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:26,代码来源:ranking_test.go
示例7: TestAggregateMethod_String
func TestAggregateMethod_String(t *testing.T) {
assert.Equal(t, "String()", Sum.String(), "Sum")
assert.Equal(t, "String()", Max.String(), "Max")
assert.Equal(t, "String()", Min.String(), "Min")
assert.Equal(t, "String()", Average.String(), "Average")
assert.Equal(t, "String()", AggregateMethod(-1).String(), "-1(invalid)")
}
开发者ID:daviddengcn,项目名称:go-easybi,代码行数:7,代码来源:counter_test.go
示例8: TestByteSlice_Bug_Read
func TestByteSlice_Bug_Read(t *testing.T) {
var s ByteSlice
n, err := s.Read(make([]byte, 1))
t.Logf("n: %d, err: %v", n, err)
assert.Equal(t, "n", 0, 0)
assert.Equal(t, "err", err, io.EOF)
}
开发者ID:postfix,项目名称:go-villa,代码行数:7,代码来源:byteslice_test.go
示例9: TestCounter_Append
func TestCounter_Append(t *testing.T) {
tests := []struct {
sum int
div int
aggr AggregateMethod
value int
final_sum int
final_div int
}{
{sum: 11, div: 4, aggr: Sum, value: 2, final_sum: 5, final_div: 1},
{sum: 11, div: 4, aggr: Min, value: 2, final_sum: 2, final_div: 1},
{sum: 11, div: 4, aggr: Max, value: 5, final_sum: 5, final_div: 1},
{sum: 11, div: 4, aggr: Average, value: 2, final_sum: 13, final_div: 5},
}
for _, test := range tests {
t.Logf("test: %v, %v", test, test.aggr)
c := Counter{
Sum: test.sum,
Div: test.div,
}
c.Append(test.aggr, test.value)
assert.Equal(t, "sum", c.Sum, test.final_sum)
assert.Equal(t, "div", c.Div, test.final_div)
}
}
开发者ID:daviddengcn,项目名称:go-easybi,代码行数:25,代码来源:counter_test.go
示例10: TestForEachPackageOfSite
func TestForEachPackageOfSite(t *testing.T) {
// Clear the database
configs.StoreBoltPath().RemoveAll()
const (
site = "TestForEachPackageOfSite.com"
path1 = "gcse"
name1 = "pkgname"
path2 = "gcse2"
name2 = "TestForEachPackageOfSite"
)
assert.NoError(t, UpdatePackage(site, path1, func(info *stpb.PackageInfo) error {
info.Name = name1
return nil
}))
assert.NoError(t, UpdatePackage(site, path2, func(info *stpb.PackageInfo) error {
info.Name = name2
return nil
}))
var paths, names []string
assert.NoError(t, ForEachPackageOfSite(site, func(path string, info *stpb.PackageInfo) error {
paths = append(paths, path)
names = append(names, info.Name)
return nil
}))
assert.Equal(t, "paths", paths, []string{path1, path2})
assert.Equal(t, "names", names, []string{name1, name2})
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:28,代码来源:store_test.go
示例11: TestMaxStackDepth
func TestMaxStackDepth(t *testing.T) {
MaxStackDepth = 1
err := WithStacks(fmt.Errorf("myerror")).(*ErrorWithStacks)
assert.Equal(t, "len(err.Stacks)", len(err.Stacks), 2)
assert.Equal(t, "err.Stacks[1]", err.Stacks[1], "...")
assert.Equal(t, "lines of err.Error()", len(strings.Split(err.Error(), "\n")), 3)
}
开发者ID:golangplus,项目名称:errors,代码行数:7,代码来源:errors_test.go
示例12: TestI
func TestI(t *testing.T) {
assert.Equal(t, "I(123)", I(123), 123)
assert.Equal(t, "I(int64(123))", I(int64(123)), 123)
assert.Equal(t, "I(abc)", I("abc"), 0)
assert.Equal(t, "I(abc, 50)", I("abc", 50), 50)
assert.Equal(t, "I(abc, def)", I("abc", "def"), 0)
}
开发者ID:jianjunliu,项目名称:gosl,代码行数:7,代码来源:builtin_test.go
示例13: TestWithStacks
func TestWithStacks(t *testing.T) {
origin := fmt.Errorf("myerror")
wrapped, isErrWithStacks := WithStacks(origin).(*ErrorWithStacks)
assert.True(t, "isErrWithStacks", isErrWithStacks)
assert.Equal(t, "wrapped.Err", wrapped.Err, origin)
wrapped2, isErrWithStacks := WithStacks(wrapped).(*ErrorWithStacks)
assert.True(t, "isErrWithStacks", isErrWithStacks)
assert.Equal(t, "wrapped2", wrapped2, wrapped)
}
开发者ID:golangplus,项目名称:errors,代码行数:10,代码来源:errors_test.go
示例14: TestRefCountBox_UnsetDataPath
func TestRefCountBox_UnsetDataPath(t *testing.T) {
fn := path.Join(os.TempDir(), "TestRefCountBox.bolt")
assert.NoError(t, os.RemoveAll(fn))
b := RefCountBox{}
db, err := b.Alloc()
assert.Equal(t, "err", errorsp.Cause(err), ErrBoxDataPathNotSpecified)
assert.ValueShould(t, "db.DB", db.DB, db.DB == nil, "is not nil")
assert.ValueShould(t, "b.db.DB", b.db.DB, b.db.DB == nil, "is not nil")
assert.Equal(t, "b.count", b.count, 0)
}
开发者ID:daviddengcn,项目名称:bolthelper,代码行数:11,代码来源:box_test.go
示例15: TestWithStacksAndMessage
func TestWithStacksAndMessage(t *testing.T) {
origin := fmt.Errorf("origin")
wrapped, isErrWithStacks := WithStacksAndMessage(origin, "%s:%d", "a", 123).(*ErrorWithStacks)
assert.True(t, "isErrWithStacks", isErrWithStacks)
assert.Equal(t, "wrapped.Err", wrapped.Err, origin)
assert.ValueShould(t, "wrapped.Stacks[0]", wrapped.Stacks[0], strings.HasSuffix(wrapped.Stacks[0], ": a:123"), "does not contain message correctly")
wrapped2, isErrWithStacks := WithStacksAndMessage(wrapped, "%s:%d", "b", 456).(*ErrorWithStacks)
assert.True(t, "isErrWithStacks", isErrWithStacks)
assert.Equal(t, "wrapped.Err", wrapped2.Err, origin)
assert.ValueShould(t, "wrapped2.Stacks[0]", wrapped2.Stacks[0], strings.HasSuffix(wrapped2.Stacks[0], ": a:123: b:456"), "does not contain message correctly")
}
开发者ID:golangplus,项目名称:errors,代码行数:12,代码来源:errors_test.go
示例16: TestSlice_ReadFrom
func TestSlice_ReadFrom(t *testing.T) {
src := make([]byte, 63*1024)
for i := range src {
src[i] = byte(i)
}
b := bytes.NewBuffer(src)
var s Slice
n, err := s.ReadFrom(b)
assert.Equal(t, "n", n, int64(len(src)))
assert.NoError(t, err)
assert.Equal(t, "s", s, Slice(src))
}
开发者ID:thomasf,项目名称:alkasir,代码行数:12,代码来源:slice_test.go
示例17: TestMoveData
func TestMoveData(t *testing.T) {
DataPath = "./tmp.bolt"
FlushPeriod = time.Second
err := os.RemoveAll(DataPath)
if err != nil && err != os.ErrNotExist {
assert.NoError(t, err)
return
}
now := time.Now()
checkValue := func(tp, name string, sum, div int) {
data, err := ReadDataOfName(tp, name)
assert.NoError(t, err)
if sum == 0 && div == 0 {
assert.Equal(t, fmt.Sprintf("%v:%v", name, tp), len(data), 0)
return
}
assert.Equal(t, fmt.Sprintf("%v:%v", name, tp), data, []LabeledCounter{{
Counter{Sum: sum, Div: div},
now.Format("2006-01-02"),
}})
}
checkNames := func(exp []string) {
names, err := ReadNames()
assert.NoError(t, err)
assert.Equal(t, "names", names, exp)
}
AddValue(Average, "TestMoveData-abc", 123)
AddValue(Average, "TestMoveData-def", 456)
Flush()
Process()
t.Log("before move")
checkNames([]string{"TestMoveData-abc", "TestMoveData-def"})
checkValue(Daily, "TestMoveData-abc", 123, 1)
checkValue(Daily, "TestMoveData-def", 456, 1)
assert.NoError(t, MoveData("TestMoveData-abc", "TestMoveData-def", Average))
t.Log("after move from abc to def")
checkNames([]string{"TestMoveData-def"})
checkValue(Daily, "TestMoveData-abc", 0, 0)
checkValue(Daily, "TestMoveData-def", 579, 2)
assert.NoError(t, MoveData("TestMoveData-def", "TestMoveData-none", Average))
t.Log("after move from def to none")
checkNames([]string{"TestMoveData-none"})
checkValue(Daily, "TestMoveData-abc", 0, 0)
checkValue(Daily, "TestMoveData-def", 0, 0)
checkValue(Daily, "TestMoveData-none", 579, 2)
}
开发者ID:daviddengcn,项目名称:go-easybi,代码行数:51,代码来源:bi_test.go
示例18: TestAppendPackageEvent
func TestAppendPackageEvent(t *testing.T) {
const (
site = "TestAppendPackageEvent.com"
path = "gcse"
foundWay = "test"
)
// Insert a found only event, no action.
foundTm := time.Now()
foundTs, _ := ptypes.TimestampProto(foundTm)
assert.NoError(t, AppendPackageEvent(site, path, "test", foundTm, sppb.HistoryEvent_Action_None))
h, err := ReadPackageHistory(site, path)
assert.NoError(t, err)
assert.Equal(t, "h", h, &sppb.HistoryInfo{FoundWay: foundWay, FoundTime: foundTs})
// Inser a Success action
succTm := foundTm.Add(time.Hour)
succTs, _ := ptypes.TimestampProto(succTm)
assert.NoError(t, AppendPackageEvent(site, path, "non-test", succTm, sppb.HistoryEvent_Action_Success))
h, err = ReadPackageHistory(site, path)
assert.NoError(t, err)
assert.Equal(t, "h", h, &sppb.HistoryInfo{
FoundWay: foundWay,
FoundTime: foundTs,
Events: []*sppb.HistoryEvent{{
Timestamp: succTs,
Action: sppb.HistoryEvent_Action_Success,
}},
LatestSuccess: succTs,
})
// Inser a Failed action
failedTm := succTm.Add(time.Hour)
failedTs, _ := ptypes.TimestampProto(failedTm)
assert.NoError(t, AppendPackageEvent(site, path, "", failedTm, sppb.HistoryEvent_Action_Failed))
h, err = ReadPackageHistory(site, path)
assert.NoError(t, err)
assert.Equal(t, "h", h, &sppb.HistoryInfo{
FoundWay: foundWay,
FoundTime: foundTs,
Events: []*sppb.HistoryEvent{{
Timestamp: failedTs,
Action: sppb.HistoryEvent_Action_Failed,
}, {
Timestamp: succTs,
Action: sppb.HistoryEvent_Action_Success,
}},
LatestSuccess: succTs,
LatestFailed: failedTs,
})
}
开发者ID:xavieryang007,项目名称:gcse,代码行数:49,代码来源:history_test.go
示例19: TestSlice_ReadFromEOF
func TestSlice_ReadFromEOF(t *testing.T) {
r1 := readerReturningEOFLastRead(1)
var s Slice
n, err := s.ReadFrom(&r1)
assert.Equal(t, "n", n, int64(1))
assert.NoError(t, err)
assert.Equal(t, "s", s, Slice([]byte{1}))
r2 := readerReturningEOFAfterLastRead(1)
s = nil
n, err = s.ReadFrom(&r2)
assert.Equal(t, "n", n, int64(1))
assert.NoError(t, err)
assert.Equal(t, "s", s, Slice([]byte{2}))
}
开发者ID:thomasf,项目名称:alkasir,代码行数:15,代码来源:slice_test.go
示例20: TestStringFull
func TestStringFull(t *testing.T) {
test := func(a, b string, d int, lcs string) {
actD, actLcs := StringFull(a, b)
assert.Equal(t, fmt.Sprintf("Edit-distance between %s and %s", a, b), actD, d)
assert.Equal(t, fmt.Sprintf("Longest-common-string between %s and %s", a, b), actLcs, lcs)
}
test("abcd", "bcde", 2, "bcd")
test("abcde", "", 5, "")
test("", "abcde", 5, "")
test("", "", 0, "")
test("abcde", "abcde", 0, "abcde")
test("abcde", "dabce", 2, "abce")
test("abcde", "abfde", 1, "abde")
}
开发者ID:daviddengcn,项目名称:go-algs,代码行数:15,代码来源:ed_test.go
注:本文中的github.com/golangplus/testing/assert.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论