erasure: Coding blocks during encoding were garbage, fixes #21

This commit is contained in:
Harshavardhana
2014-11-13 21:48:04 -08:00
parent c39c51328e
commit 6a6dac8365
5 changed files with 35 additions and 37 deletions
+10 -15
View File
@@ -18,33 +18,30 @@ package erasure
import (
"bytes"
"testing"
. "gopkg.in/check.v1"
)
func TestVanderMondeEncode(t *testing.T) {
func (s *MySuite) TestVanderMondeEncode(c *C) {
ep, _ := ValidateParams(10, 5, 8, VANDERMONDE)
p := NewEncoder(ep)
data := make([]byte, 1000)
chunks, length := p.Encode(data)
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
if length != len(data) {
t.Fatal()
}
c.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
c.Assert(length, Equals, len(data))
}
func TestVanderMondeDecode(t *testing.T) {
func (s *MySuite) TestVanderMondeDecode(c *C) {
ep, _ := ValidateParams(10, 5, 8, VANDERMONDE)
p := NewEncoder(ep)
data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
chunks, length := p.Encode(data)
t.Logf("chunks length: %d;\nlength: %d\n", len(chunks), length)
if length != len(data) {
t.Fatal()
}
c.Logf("chunks length: %d", len(chunks))
c.Logf("length: %d", length)
c.Assert(length, Equals, len(data))
chunks[0] = nil
chunks[3] = nil
@@ -53,11 +50,9 @@ func TestVanderMondeDecode(t *testing.T) {
chunks[13] = nil
recovered_data, err := p.Decode(chunks, length)
if err != nil {
t.Fatalf("Error: %s", err)
}
c.Assert(err, Not(IsNil))
if i := bytes.Compare(recovered_data, data); i < 0 {
t.Fatalf("Error: recovered data is less than original data")
c.Fatalf("Error: recovered data is less than original data")
}
}