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
parent
cf985d4451
commit
64b705bbf6
|
@ -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++ {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue