本文整理汇总了Golang中bytes.Repeat函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Repeat函数的具体用法?Golang Repeat怎么用?Golang Repeat使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了Repeat函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: TestChaChaCorrectness
func TestChaChaCorrectness(t *testing.T) {
ec, dc := initChaCha(20)
sample = bytes.Repeat(origin, 100)
origin = bytes.Repeat(origin, 100)
randChip("dec", sample, func(chip []byte) {
ec.XORKeyStream(chip, chip)
})
dc.XORKeyStream(sample, sample)
if !bytes.Equal(origin, sample) {
dumpHex(sample, "result")
dumpHex(origin, "origin")
t.Fatalf("Incorrect result")
}
ec.XORKeyStream(sample, sample)
randChip("dec", sample, func(chip []byte) {
dc.XORKeyStream(chip, chip)
})
if !bytes.Equal(origin, sample) {
dumpHex(sample, "result")
dumpHex(origin, "origin")
t.Fatalf("Incorrect result")
}
}
开发者ID:ygcoffice,项目名称:deblocus,代码行数:29,代码来源:chacha_test.go
示例2: TestWriteAtom
func TestWriteAtom(t *testing.T) {
c := new(Context)
test := func(in Atom, shouldFail bool) {
w := new(bytes.Buffer)
if err := c.writeAtom(w, in); err != nil {
if !shouldFail {
t.Error(in, err)
}
} else if shouldFail {
t.Error("err == nil (%v)", in)
} else if v, err := c.Read(w); err != nil {
t.Error(in, err)
} else if l := w.Len(); l != 0 {
t.Errorf("%v: buffer len %d", in, l)
} else if v != in {
t.Errorf("expected %v, got %v", in, v)
}
}
test(Atom(""), false)
test(Atom(bytes.Repeat([]byte{'a'}, math.MaxUint8)), false)
test(Atom(bytes.Repeat([]byte{'a'}, math.MaxUint8+1)), false)
test(Atom(bytes.Repeat([]byte{'a'}, math.MaxUint16)), false)
test(Atom(bytes.Repeat([]byte{'a'}, math.MaxUint16+1)), true)
}
开发者ID:agelin,项目名称:etf,代码行数:25,代码来源:write_test.go
示例3: TestUnencryptedSuffix
func TestUnencryptedSuffix(t *testing.T) {
branch := TreeBranch{
TreeItem{
Key: "foo_unencrypted",
Value: "bar",
},
}
tree := Tree{Branch: branch, Metadata: Metadata{UnencryptedSuffix: "_unencrypted"}}
expected := TreeBranch{
TreeItem{
Key: "foo_unencrypted",
Value: "bar",
},
}
cipher := aes.Cipher{}
_, err := tree.Encrypt(bytes.Repeat([]byte("f"), 32), cipher)
if err != nil {
t.Errorf("Encrypting the tree failed: %s", err)
}
if !reflect.DeepEqual(tree.Branch, expected) {
t.Errorf("Trees don't match: \ngot \t\t%+v,\n expected \t\t%+v", tree.Branch, expected)
}
_, err = tree.Decrypt(bytes.Repeat([]byte("f"), 32), cipher)
if err != nil {
t.Errorf("Decrypting the tree failed: %s", err)
}
if !reflect.DeepEqual(tree.Branch, expected) {
t.Errorf("Trees don't match: \ngot\t\t\t%+v,\nexpected\t\t%+v", tree.Branch, expected)
}
}
开发者ID:mozilla-services,项目名称:userplex,代码行数:30,代码来源:sops_test.go
示例4: BenchmarkDeserializeTxLarge
// BenchmarkDeserializeTxLarge performs a benchmark on how long it takes to
// deserialize a very large transaction.
func BenchmarkDeserializeTxLarge(b *testing.B) {
bigTx := new(MsgTx)
bigTx.Version = DefaultMsgTxVersion()
inputsLen := 1000
outputsLen := 2000
bigTx.TxIn = make([]*TxIn, inputsLen)
bigTx.TxOut = make([]*TxOut, outputsLen)
for i := 0; i < inputsLen; i++ {
bigTx.TxIn[i] = &TxIn{
SignatureScript: bytes.Repeat([]byte{0x12}, 120),
}
}
for i := 0; i < outputsLen; i++ {
bigTx.TxOut[i] = &TxOut{
PkScript: bytes.Repeat([]byte{0x34}, 30),
}
}
bigTxB, err := bigTx.Bytes()
if err != nil {
b.Fatalf("%v", err.Error())
}
r := bytes.NewReader(bigTxB)
var tx MsgTx
for i := 0; i < b.N; i++ {
r.Seek(0, 0)
tx.Deserialize(r)
}
}
开发者ID:decred,项目名称:dcrd,代码行数:31,代码来源:bench_test.go
示例5: TestGetApproximateOffsetPlain
func TestGetApproximateOffsetPlain(t *testing.T) {
w := new(writer)
o := &opt.Options{
BlockSize: 1024,
Compression: opt.NoCompression,
}
tw := NewWriter(w, o)
tw.Append([]byte("k01"), []byte("hello"))
tw.Append([]byte("k02"), []byte("hello2"))
tw.Append([]byte("k03"), bytes.Repeat([]byte{'x'}, 10000))
tw.Append([]byte("k04"), bytes.Repeat([]byte{'x'}, 200000))
tw.Append([]byte("k05"), bytes.Repeat([]byte{'x'}, 300000))
tw.Append([]byte("k06"), []byte("hello3"))
tw.Append([]byte("k07"), bytes.Repeat([]byte{'x'}, 100000))
if err := tw.Close(); err != nil {
t.Fatal("error when finalizing table:", err.Error())
}
size := w.Len()
r := &reader{*bytes.NewReader(w.Bytes())}
tr := NewReader(r, int64(size), nil, o)
// if err != nil {
// t.Fatal("error when creating table reader instance:", err.Error())
// }
offsetBetween(t, tr, []byte("k0"), 0, 0)
offsetBetween(t, tr, []byte("k01a"), 0, 0)
offsetBetween(t, tr, []byte("k02"), 0, 0)
offsetBetween(t, tr, []byte("k03"), 0, 0)
offsetBetween(t, tr, []byte("k04"), 10000, 11000)
offsetBetween(t, tr, []byte("k04a"), 210000, 211000)
offsetBetween(t, tr, []byte("k05"), 210000, 211000)
offsetBetween(t, tr, []byte("k06"), 510000, 511000)
offsetBetween(t, tr, []byte("k07"), 510000, 511000)
offsetBetween(t, tr, []byte("xyz"), 610000, 612000)
}
开发者ID:pombredanne,项目名称:goleveldb,代码行数:35,代码来源:table_test.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng