You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
b:=MakeC2Buffer(BLOCK_SIZE)
b.Write(incrementBlock)
b.Write(incrementBlock2)
ifbytes.Compare(b.GetBlock(), incrementBlock2) !=0 {
t.Errorf("Get block did not return the right value: %s", b.GetBlock())
}
TestWriteSingleByteGetSingleByte
b:=MakeC2Buffer(BLOCK_SIZE)
singleByte:= []byte{0}
b.Write(singleByte)
ifbytes.Compare(b.GetBlock(), singleByte) !=0 {
t.Errorf("Get block did not return the right value: %s", b.GetBlock())
}
TestWriteTwoBlocksGetEvicted
b:=MakeC2Buffer(BLOCK_SIZE)
b.Write(incrementBlock)
b.Write(incrementBlock2)
ifbytes.Compare(b.Evicted(), incrementBlock) !=0 {
t.Errorf("Evicted did not return the right value: %s", b.Evicted())
}
TestWriteSingleByteReturnsSingleEvictedByte
b:=MakeC2Buffer(BLOCK_SIZE)
b.Write(incrementBlock2)
singleByte:= []byte{0}
b.Write(singleByte)
e:=b.Evicted()
iflen(e) !=1 {
t.Fatalf("Evicted length is not correct: %s", e)
}
ife[0] !=byte(10) {
t.Errorf("Evicted content is not correct: %s", e)
}
TestTruncatingAfterWriting
b:=MakeC2Buffer(BLOCK_SIZE)
b.Write(incrementBlock)
evicted:=b.Truncate(2)
iflen(evicted) !=2 {
t.Fatalf("Truncate did not return expected evicted length: %v", evicted)
}
ifevicted[0] !=0||evicted[1] !=1 {
t.Errorf("Unexpected content in evicted: %v", evicted)
}
TestWritingAfterTruncating
// test that after we truncate some content, the next operations// on the buffer give us the expected resultsb:=MakeC2Buffer(BLOCK_SIZE)
b.Write(incrementBlock)
b.Truncate(4)
b.Write([]byte{34, 46})
block:=b.GetBlock()
iflen(block) !=BLOCK_SIZE-2 {
t.Fatalf(
"Unexpected block length after truncation: %v (%v)",
block,
len(block),
)
}
ifbytes.Compare(block, []byte{4, 5, 6, 7, 8, 9, 34, 46}) !=0 {
t.Errorf(
"Unexpected block content after truncation: %v (%v)",
block,
len(block))
}
crc16-kermit_test.go
TestKermit
a:=Kermit([]byte("abcdefg汉字"))
b:=Kermit([]byte("abcdefg汉字"))
ifa!=b {
t.Error(a, b)
}