本文整理汇总了Golang中github.com/attic-labs/testify/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestPanicIfTrue
func TestPanicIfTrue(t *testing.T) {
assert := assert.New(t)
arg := "arg value"
format := "could be a format: %s"
formatted := fmt.Sprintf(format, arg)
assert.Panics(func() {
PanicIfTrue(true, "Panicking!!!!")
})
assert.NotPanics(func() {
PanicIfTrue(false, "Not panicking")
})
err := Try(func() {
PanicIfTrue(true, format)
})
assert.Equal(errors.New(format), Unwrap(err))
err = Try(func() {
PanicIfTrue(true, format, arg)
})
assert.Equal(errors.New(formatted), Unwrap(err))
}
开发者ID:Richardphp,项目名称:noms,代码行数:25,代码来源:try_test.go
示例2: TestMapTypeAfterMutations
func TestMapTypeAfterMutations(t *testing.T) {
assert := assert.New(t)
test := func(n int, c interface{}) {
values := make([]Value, 2*n)
for i := 0; i < n; i++ {
values[2*i] = Number(i)
values[2*i+1] = Number(i)
}
m := NewMap(values...)
assert.Equal(m.Len(), uint64(n))
assert.IsType(c, m.sequence())
assert.True(m.Type().Equals(MakeMapType(NumberType, NumberType)))
m = m.Set(String("a"), String("a"))
assert.Equal(m.Len(), uint64(n+1))
assert.IsType(c, m.sequence())
assert.True(m.Type().Equals(MakeMapType(MakeUnionType(NumberType, StringType), MakeUnionType(NumberType, StringType))))
m = m.Remove(String("a"))
assert.Equal(m.Len(), uint64(n))
assert.IsType(c, m.sequence())
assert.True(m.Type().Equals(MakeMapType(NumberType, NumberType)))
}
test(10, mapLeafSequence{})
test(1000, orderedMetaSequence{})
}
开发者ID:Richardphp,项目名称:noms,代码行数:29,代码来源:map_test.go
示例3: TestBuildWriteValueRequest
func TestBuildWriteValueRequest(t *testing.T) {
assert := assert.New(t)
input1, input2 := "abc", "def"
chnx := []chunks.Chunk{
chunks.NewChunk([]byte(input1)),
chunks.NewChunk([]byte(input2)),
}
hints := map[hash.Hash]struct{}{
hash.Parse("sha1-0000000000000000000000000000000000000002"): struct{}{},
hash.Parse("sha1-0000000000000000000000000000000000000003"): struct{}{},
}
compressed := buildWriteValueRequest(serializeChunks(chnx, assert), hints)
gr := snappy.NewReader(compressed)
count := 0
for hint := range deserializeHints(gr) {
count++
_, present := hints[hint]
assert.True(present)
}
assert.Equal(len(hints), count)
chunkChan := make(chan *chunks.Chunk, 16)
go chunks.DeserializeToChan(gr, chunkChan)
for c := range chunkChan {
assert.Equal(chnx[0].Hash(), c.Hash())
chnx = chnx[1:]
}
assert.Empty(chnx)
}
开发者ID:willhite,项目名称:noms-old,代码行数:31,代码来源:remote_database_handlers_test.go
示例4: TestStringString
func TestStringString(t *testing.T) {
assert := assert.New(t)
s1 := String("")
s2 := String("foo")
assert.Equal("", string(s1))
assert.Equal("foo", string(s2))
}
开发者ID:willhite,项目名称:noms-old,代码行数:7,代码来源:string_test.go
示例5: TestListDiffRemove5x100
func TestListDiffRemove5x100(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
t.Parallel()
assert := assert.New(t)
nums1 := generateNumbersAsValues(5000)
nums2 := generateNumbersAsValues(5000)
for count := 5; count > 0; count-- {
nums2 = spliceValues(nums2, (count-1)*1000, 100)
}
l1 := NewList(nums1...)
l2 := NewList(nums2...)
diff1 := l1.Diff(l2)
diff2 := l2.Diff(l1)
assert.Equal(len(diff1), len(diff2))
diff2Expected := []Splice{
Splice{0, 100, 0, 0},
Splice{1000, 100, 0, 0},
Splice{2000, 100, 0, 0},
Splice{3000, 100, 0, 0},
Splice{4000, 100, 0, 0},
}
assert.Equal(diff2Expected, diff2, "expected diff is wrong")
}
开发者ID:willhite,项目名称:noms-old,代码行数:26,代码来源:list_test.go
示例6: TestSetTypeAfterMutations
func TestSetTypeAfterMutations(t *testing.T) {
assert := assert.New(t)
smallTestChunks()
defer normalProductionChunks()
test := func(n int, c interface{}) {
values := generateNumbersAsValues(n)
s := NewSet(values...)
assert.Equal(s.Len(), uint64(n))
assert.IsType(c, s.sequence())
assert.True(s.Type().Equals(MakeSetType(NumberType)))
s = s.Insert(String("a"))
assert.Equal(s.Len(), uint64(n+1))
assert.IsType(c, s.sequence())
assert.True(s.Type().Equals(MakeSetType(MakeUnionType(NumberType, StringType))))
s = s.Remove(String("a"))
assert.Equal(s.Len(), uint64(n))
assert.IsType(c, s.sequence())
assert.True(s.Type().Equals(MakeSetType(NumberType)))
}
test(10, setLeafSequence{})
test(2000, orderedMetaSequence{})
}
开发者ID:Richardphp,项目名称:noms,代码行数:28,代码来源:set_test.go
示例7: TestHandleGetRefs
func TestHandleGetRefs(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
input1, input2 := "abc", "def"
chnx := []chunks.Chunk{
chunks.NewChunk([]byte(input1)),
chunks.NewChunk([]byte(input2)),
}
err := cs.PutMany(chnx)
assert.NoError(err)
body := strings.NewReader(fmt.Sprintf("ref=%s&ref=%s", chnx[0].Hash(), chnx[1].Hash()))
w := httptest.NewRecorder()
HandleGetRefs(w,
&http.Request{Body: ioutil.NopCloser(body), Method: "POST", Header: http.Header{
"Content-Type": {"application/x-www-form-urlencoded"},
}},
params{},
cs,
)
if assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
chunkChan := make(chan *chunks.Chunk)
go chunks.DeserializeToChan(w.Body, chunkChan)
for c := range chunkChan {
assert.Equal(chnx[0].Hash(), c.Hash())
chnx = chnx[1:]
}
assert.Empty(chnx)
}
}
开发者ID:willhite,项目名称:noms-old,代码行数:32,代码来源:remote_database_handlers_test.go
示例8: TestListDiffAdd5x5
func TestListDiffAdd5x5(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
smallTestChunks()
defer normalProductionChunks()
assert := assert.New(t)
nums1 := generateNumbersAsValues(5000)
nums2 := generateNumbersAsValues(5000)
for count := 5; count > 0; count-- {
nums2 = spliceValues(nums2, (count-1)*1000, 0, Number(0), Number(1), Number(2), Number(3), Number(4))
}
l1 := NewList(nums1...)
l2 := NewList(nums2...)
diff1 := accumulateDiffSplices(l1, l2)
diff2 := accumulateDiffSplices(l2, l1)
assert.Equal(len(diff1), len(diff2))
diff2Expected := []Splice{
Splice{5, 0, 5, 5},
Splice{1000, 0, 5, 1005},
Splice{2000, 0, 5, 2010},
Splice{3000, 0, 5, 3015},
Splice{4000, 0, 5, 4020},
}
assert.Equal(diff2Expected, diff2, "expected diff is wrong")
}
开发者ID:Richardphp,项目名称:noms,代码行数:30,代码来源:list_test.go
示例9: TestListDiffReverseWithLargerLimit
func TestListDiffReverseWithLargerLimit(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
smallTestChunks()
defer normalProductionChunks()
assert := assert.New(t)
nums1 := generateNumbersAsValues(5000)
nums2 := reverseValues(nums1)
l1 := NewList(nums1...)
l2 := NewList(nums2...)
diff1 := accumulateDiffSplicesWithLimit(l1, l2, 27e6)
diff2 := accumulateDiffSplicesWithLimit(l2, l1, 27e6)
assert.Equal(len(diff2), len(diff1))
diffExpected := []Splice{
Splice{0, 2499, 2500, 0},
Splice{2500, 2500, 2499, 2501},
}
assert.Equal(diffExpected, diff1, "expected diff is wrong")
assert.Equal(diffExpected, diff2, "expected diff is wrong")
}
开发者ID:Richardphp,项目名称:noms,代码行数:25,代码来源:list_test.go
示例10: TestBlobSplice
func TestBlobSplice(t *testing.T) {
assert := assert.New(t)
blob := NewEmptyBlob()
buf := new(bytes.Buffer)
blob = blob.Splice(0, 0, []byte("I'll do anything"))
buf.Reset()
buf.ReadFrom(blob.Reader())
assert.Equal(buf.String(), "I'll do anything")
blob = blob.Splice(16, 0, []byte(" for arv"))
buf.Reset()
buf.ReadFrom(blob.Reader())
assert.Equal(buf.String(), "I'll do anything for arv")
blob = blob.Splice(0, 0, []byte("Yes, "))
buf.Reset()
buf.ReadFrom(blob.Reader())
assert.Equal(buf.String(), "Yes, I'll do anything for arv")
blob = blob.Splice(5, 20, []byte("it's hard to satisfy"))
buf.Reset()
buf.ReadFrom(blob.Reader())
assert.Equal(buf.String(), "Yes, it's hard to satisfy arv")
}
开发者ID:Richardphp,项目名称:noms,代码行数:26,代码来源:blob_test.go
示例11: TestIncrementalLoadList
func TestIncrementalLoadList(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
vs := newLocalValueStore(cs)
expected := NewList(testVals...)
ref := vs.WriteValue(expected).TargetHash()
actualVar := vs.ReadValue(ref)
actual := actualVar.(List)
expectedCount := cs.Reads
assert.Equal(1, expectedCount)
// There will be one read per chunk.
chunkReads := make([]int, expected.Len())
for i := uint64(0); i < expected.Len(); i++ {
v := actual.Get(i)
assert.True(expected.Get(i).Equals(v))
expectedCount += isEncodedOutOfLine(v)
assert.Equal(expectedCount+chunkReads[i], cs.Reads)
// Do it again to make sure multiple derefs don't do multiple loads.
v = actual.Get(i)
assert.Equal(expectedCount+chunkReads[i], cs.Reads)
}
}
开发者ID:willhite,项目名称:noms-old,代码行数:27,代码来源:incremental_test.go
示例12: TestLDBObject
func TestLDBObject(t *testing.T) {
assert := assert.New(t)
dir, err := ioutil.TempDir(os.TempDir(), "")
assert.NoError(err)
ldbpath := path.Join(dir, "xx-yy")
dsId := "dsId"
cs1 := chunks.NewLevelDBStoreUseFlags(ldbpath, "")
store1 := datas.NewDatabase(cs1)
dataset1 := dataset.NewDataset(store1, dsId)
s1 := types.String("Commit Value")
r1 := store1.WriteValue(s1)
_, err = dataset1.Commit(r1)
assert.NoError(err)
store1.Close()
spec2 := fmt.Sprintf("ldb:%s::%s", ldbpath, dsId)
assert.NoError(err)
sp1, err := ParseDatasetSpec(spec2)
assert.NoError(err)
dataset2, err := sp1.Dataset()
assert.NoError(err)
r2 := dataset2.HeadValue()
s2 := r2.(types.Ref).TargetValue(dataset2.Database())
assert.Equal(s1, s2)
dataset2.Database().Close()
spec3 := fmt.Sprintf("ldb:%s::%s", ldbpath, s1.Hash().String())
sp3, err := ParsePathSpec(spec3)
database, v3, err := sp3.Value()
assert.Equal(s1, v3)
database.Close()
}
开发者ID:willhite,项目名称:noms-old,代码行数:33,代码来源:dataspec_test.go
示例13: TestHandleWriteValueBackpressure
func TestHandleWriteValueBackpressure(t *testing.T) {
assert := assert.New(t)
cs := &backpressureCS{ChunkStore: chunks.NewMemoryStore()}
ds := NewDatabase(cs)
l := types.NewList(
ds.WriteValue(types.Bool(true)),
ds.WriteValue(types.Bool(false)),
)
ds.WriteValue(l)
hint := l.Hash()
newItem := types.NewEmptyBlob()
itemChunk := types.EncodeValue(newItem, nil)
l2 := l.Insert(1, types.NewRef(newItem))
listChunk := types.EncodeValue(l2, nil)
body := &bytes.Buffer{}
serializeHints(body, map[hash.Hash]struct{}{hint: struct{}{}})
sz := chunks.NewSerializer(body)
sz.Put(itemChunk)
sz.Put(listChunk)
sz.Close()
w := httptest.NewRecorder()
HandleWriteValue(w, &http.Request{Body: ioutil.NopCloser(body), Method: "POST"}, params{}, cs)
if assert.Equal(httpStatusTooManyRequests, w.Code, "Handler error:\n%s", string(w.Body.Bytes())) {
hashes := deserializeHashes(w.Body)
assert.Len(hashes, 1)
assert.Equal(l2.Hash(), hashes[0])
}
}
开发者ID:willhite,项目名称:noms-old,代码行数:33,代码来源:remote_database_handlers_test.go
示例14: SkipTestIncrementalAddRef
func SkipTestIncrementalAddRef(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
vs := newLocalValueStore(cs)
expectedItem := Number(42)
ref := vs.WriteValue(expectedItem)
expected := NewList(ref)
ref = vs.WriteValue(expected)
actualVar := vs.ReadValue(ref.TargetHash())
assert.Equal(1, cs.Reads)
assert.True(expected.Equals(actualVar))
actual := actualVar.(List)
actualItem := actual.Get(0)
assert.Equal(2, cs.Reads)
assert.True(expectedItem.Equals(actualItem))
// do it again to make sure caching works.
actualItem = actual.Get(0)
assert.Equal(2, cs.Reads)
assert.True(expectedItem.Equals(actualItem))
}
开发者ID:willhite,项目名称:noms-old,代码行数:25,代码来源:incremental_test.go
示例15: TestHeadValueFunctions
func TestHeadValueFunctions(t *testing.T) {
assert := assert.New(t)
id1 := "testdataset"
id2 := "otherdataset"
cs := chunks.NewMemoryStore()
ds1 := newDS(id1, cs)
// ds1: |a|
a := types.String("a")
ds1, err := ds1.CommitValue(a)
assert.NoError(err)
hv := ds1.Head().Get(datas.ValueField)
assert.Equal(a, hv)
assert.Equal(a, ds1.HeadValue())
hv, ok := ds1.MaybeHeadValue()
assert.True(ok)
assert.Equal(a, hv)
ds2 := newDS(id2, cs)
assert.Panics(func() {
ds2.HeadValue()
})
_, ok = ds2.MaybeHeadValue()
assert.False(ok)
}
开发者ID:Richardphp,项目名称:noms,代码行数:29,代码来源:dataset_test.go
示例16: TestConstructQueryString
func TestConstructQueryString(t *testing.T) {
assert := assert.New(t)
prefix := "TestConstructQueryString"
d1, e1 := ioutil.TempDir(os.TempDir(), prefix)
defer os.RemoveAll(d1)
d2, e2 := ioutil.TempDir(os.TempDir(), prefix)
defer os.RemoveAll(d2)
assert.NoError(e1)
assert.NoError(e2)
qs, stores := constructQueryString([]string{
"foo=bar",
"store1=ldb:" + d1,
"store2=ldb:" + d2,
"store3=ldb:" + d1,
"hello=world",
})
assert.Equal(5, len(qs))
assert.Equal("bar", qs.Get("foo"))
assert.True(strings.HasPrefix(qs.Get("store1"), dsPathPrefix))
assert.True(strings.HasPrefix(qs.Get("store2"), dsPathPrefix))
assert.True(strings.HasPrefix(qs.Get("store3"), dsPathPrefix))
assert.Equal(qs.Get("store1"), qs.Get("store3"))
assert.NotEqual(qs.Get("store1"), qs.Get("store2"))
assert.Equal(2, len(stores))
}
开发者ID:Richardphp,项目名称:noms,代码行数:29,代码来源:noms_ui_test.go
示例17: TestFindCommon
// Note: This test is asserting that findCommon correctly separates refs which are exclusive to |taller| from those which are |common|.
func TestFindCommon(t *testing.T) {
taller := &types.RefByHeight{}
shorter := &types.RefByHeight{}
for i := 0; i < 50; i++ {
shorter.PushBack(types.NewRef(types.Number(i)))
}
for i := 50; i < 250; i++ {
shorter.PushBack(types.NewRef(types.Number(i)))
taller.PushBack(types.NewRef(types.Number(i)))
}
for i := 250; i < 275; i++ {
taller.PushBack(types.NewRef(types.Number(i)))
}
sort.Sort(shorter)
sort.Sort(taller)
tallRefs, comRefs := findCommon(taller, shorter, 1)
assert.Equal(t, 25, len(tallRefs))
assert.Equal(t, 200, len(comRefs))
assert.Equal(t, 0, len(*taller))
assert.Equal(t, 50, len(*shorter))
}
开发者ID:Richardphp,项目名称:noms,代码行数:27,代码来源:pull_test.go
示例18: TestListTypeAfterMutations
func TestListTypeAfterMutations(t *testing.T) {
smallTestChunks()
defer normalProductionChunks()
assert := assert.New(t)
test := func(n int, c interface{}) {
values := generateNumbersAsValues(n)
l := NewList(values...)
assert.Equal(l.Len(), uint64(n))
assert.IsType(c, l.sequence())
assert.True(l.Type().Equals(MakeListType(NumberType)))
l = l.Append(String("a"))
assert.Equal(l.Len(), uint64(n+1))
assert.IsType(c, l.sequence())
assert.True(l.Type().Equals(MakeListType(MakeUnionType(NumberType, StringType))))
l = l.Splice(l.Len()-1, 1)
assert.Equal(l.Len(), uint64(n))
assert.IsType(c, l.sequence())
assert.True(l.Type().Equals(MakeListType(NumberType)))
}
test(15, listLeafSequence{})
test(1500, indexedMetaSequence{})
}
开发者ID:Richardphp,项目名称:noms,代码行数:28,代码来源:list_test.go
示例19: TestHandlePostRoot
func TestHandlePostRoot(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
vs := types.NewValueStore(types.NewBatchStoreAdaptor(cs))
commit := NewCommit(types.String("head"), types.NewSet(), types.NewStruct("Meta", types.StructData{}))
newHead := types.NewMap(types.String("dataset1"), vs.WriteValue(commit))
chnx := []chunks.Chunk{
chunks.NewChunk([]byte("abc")),
types.EncodeValue(newHead, nil),
}
err := cs.PutMany(chnx)
assert.NoError(err)
// First attempt should fail, as 'last' won't match.
u := &url.URL{}
queryParams := url.Values{}
queryParams.Add("last", chnx[0].Hash().String())
queryParams.Add("current", chnx[1].Hash().String())
u.RawQuery = queryParams.Encode()
url := u.String()
w := httptest.NewRecorder()
HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs)
assert.Equal(http.StatusConflict, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
// Now, update the root manually to 'last' and try again.
assert.True(cs.UpdateRoot(chnx[0].Hash(), hash.Hash{}))
w = httptest.NewRecorder()
HandleRootPost(w, newRequest("POST", "", url, nil, nil), params{}, cs)
assert.Equal(http.StatusOK, w.Code, "Handler error:\n%s", string(w.Body.Bytes()))
}
开发者ID:Richardphp,项目名称:noms,代码行数:32,代码来源:remote_database_handlers_test.go
示例20: TestListRemoveRanges
func TestListRemoveRanges(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test in short mode.")
}
assert := assert.New(t)
smallTestChunks()
defer normalProductionChunks()
testList := getTestList()
whole := testList.toList()
// Compare list equality. Increment by 256 (16^2) because each iteration requires building a new list, which is slow.
for incr, i := 256, 0; i < len(testList)-incr; i += incr {
for window := 1; window <= incr; window *= 16 {
testListPart := testList.Remove(i, i+window)
expected := testListPart.toList()
actual := whole.Remove(uint64(i), uint64(i+window))
assert.Equal(expected.Len(), actual.Len())
assert.True(expected.Equals(actual))
}
}
// Compare list length, which doesn't require building a new list every iteration, so the increment can be smaller.
for incr, i := 10, 0; i < len(testList)-incr; i += incr {
assert.Equal(len(testList)-incr, int(whole.Remove(uint64(i), uint64(i+incr)).Len()))
}
}
开发者ID:Richardphp,项目名称:noms,代码行数:28,代码来源:list_test.go
注:本文中的github.com/attic-labs/testify/assert.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论