Skip to content

Commit

Permalink
test: decoder_result_size_hint
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersTrier committed Nov 25, 2024
1 parent c00bcf1 commit fbb7aa6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/decoder_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,39 @@ mod tests {
simple_roundtrip(shard_size);
}
}

#[test]
fn decoder_result_size_hint() {
let shard_size = 64;
let original = test_util::generate_original(3, shard_size, 0);

let mut encoder = ReedSolomonEncoder::new(3, 2, shard_size).unwrap();
let mut decoder = ReedSolomonDecoder::new(3, 2, shard_size).unwrap();

for original in &original {
encoder.add_original_shard(original).unwrap();
}

let result = encoder.encode().unwrap();
let recovery: Vec<_> = result.recovery_iter().collect();

decoder.add_original_shard(1, &original[1]).unwrap();
decoder.add_recovery_shard(0, recovery[0]).unwrap();
decoder.add_recovery_shard(1, recovery[1]).unwrap();

let result: DecoderResult = decoder.decode().unwrap();

let mut iter: RestoredOriginal = result.restored_original_iter();

assert_eq!(iter.len(), 2);

assert!(iter.next().is_some());
assert_eq!(iter.len(), 1);

assert!(iter.next().is_some());
assert_eq!(iter.len(), 0);

assert!(iter.next().is_none());
assert_eq!(iter.len(), 0);
}
}

0 comments on commit fbb7aa6

Please sign in to comment.