fully test Reconstruct function

Well, I can't figure out how to trigger the Invert error.
It may not be possible; need more domain knowledge to be sure.
master
lukechampine 2015-08-06 23:24:15 -04:00
parent cf985d4451
commit 64b705bbf6
2 changed files with 28 additions and 4 deletions

View File

@ -388,10 +388,7 @@ func (r reedSolomon) Reconstruct(shards [][]byte) error {
// correspond to the rows of the submatrix. These shards
// will be the input to the decoding process that re-creates
// the missing data shards.
subMatrix, err := newMatrix(r.DataShards, r.DataShards)
if err != nil {
return err
}
subMatrix, _ := newMatrix(r.DataShards, r.DataShards)
subShards := make([][]byte, r.DataShards)
subMatrixRow := 0
for matrixRow := 0; matrixRow < r.Shards && subMatrixRow < r.DataShards; matrixRow++ {

View File

@ -75,6 +75,13 @@ func TestReconstruct(t *testing.T) {
t.Fatal(err)
}
// Reconstruct with all shards present
err = r.Reconstruct(shards)
if err != nil {
t.Fatal(err)
}
// Reconstruct with 10 shards present
shards[0] = nil
shards[7] = nil
shards[11] = nil
@ -91,6 +98,26 @@ func TestReconstruct(t *testing.T) {
if !ok {
t.Fatal("Verification failed")
}
// Reconstruct with 9 shards present (should fail)
shards[0] = nil
shards[4] = nil
shards[7] = nil
shards[11] = nil
err = r.Reconstruct(shards)
if err != ErrTooFewShards {
t.Errorf("expected %v, got %v", ErrTooFewShards, err)
}
err = r.Reconstruct(make([][]byte, 1))
if err != ErrTooFewShards {
t.Errorf("expected %v, got %v", ErrTooFewShards, err)
}
err = r.Reconstruct(make([][]byte, 13))
if err != ErrShardNoData {
t.Errorf("expected %v, got %v", ErrShardNoData, err)
}
}
func TestVerify(t *testing.T) {