Skip to content
Snippets Groups Projects

complete the FEC and "linear algebra" tests

Merged STEVAN Antoine requested to merge more-tests into main
+ 38
26
@@ -200,7 +200,7 @@ mod tests {
use ark_ff::PrimeField;
use crate::{
fec::{decode, encode, Shard},
fec::{decode, encode, recode_random, Shard},
field,
linalg::Matrix,
};
@@ -217,24 +217,28 @@ mod tests {
F::from_le_bytes_mod_order(&n.to_le_bytes())
}
fn is_inside(set: &[Vec<usize>], x: &[usize]) -> bool {
/// `contains_one_of(x, set)` is true iif `x` fully contains one of the lists from `set`
///
/// > **Note**
/// > see [`containment`] for some example
fn contains_one_of(x: &[usize], set: &[Vec<usize>]) -> bool {
set.iter().any(|y| y.iter().all(|z| x.contains(z)))
}
#[test]
fn exclusion() {
assert!(is_inside(&[vec![1, 2, 3]], &[1, 2, 3]));
assert!(is_inside(
fn containment() {
assert!(contains_one_of(&[1, 2, 3], &[vec![1, 2, 3]]));
assert!(contains_one_of(
&[3, 6, 8],
&[vec![2, 4, 6], vec![1, 3, 7], vec![6, 7, 8], vec![3, 6, 8]],
&[3, 6, 8]
));
assert!(!is_inside(
assert!(!contains_one_of(
&[1, 6, 8],
&[vec![2, 4, 6], vec![1, 3, 7], vec![6, 7, 8], vec![3, 6, 8]],
&[1, 6, 8]
));
assert!(is_inside(
assert!(contains_one_of(
&[3, 6, 8, 9, 10],
&[vec![2, 4, 6], vec![1, 3, 7], vec![6, 7, 8], vec![3, 6, 8]],
&[3, 6, 8, 9, 10]
));
}
@@ -244,7 +248,7 @@ mod tests {
k: usize,
test_case: &str,
limit: Option<usize>,
exclude: Vec<Vec<usize>>,
should_not_be_decodable: Vec<Vec<usize>>,
) {
for c in shards
.iter()
@@ -258,7 +262,7 @@ mod tests {
let actual = decode::<F>(s);
if is_inside(&exclude, &is) {
if contains_one_of(&is, &should_not_be_decodable) {
assert!(
actual.is_err(),
"should not decode with {:?} {test_case}",
@@ -297,21 +301,29 @@ mod tests {
let shards = encode::<F>(data, &Matrix::random(k, n, &mut rng));
assert!(shards.is_ok(), "could not encode {test_case}");
let recoding_steps = [
[2, 4], // = n
[1, 3], // = (n + 1)
[n, (n + 1)], // = (n + 2) = ((2, 4), (1, 3))
];
let should_not_be_decodable = vec![
vec![2, 4, n],
vec![1, 3, (n + 1)],
vec![n, (n + 1), (n + 2)],
];
let mut shards = shards.unwrap();
shards.push(shards[2].recode_with(to_curve(7), &shards[4], to_curve(6)));
shards.push(shards[1].recode_with(to_curve(5), &shards[3], to_curve(4)));
// n = (2, 4)
// n + 1 = (1, 3)
try_all_decoding_combinations(
data,
&shards,
k,
&test_case,
None,
vec![vec![2, 4, n], vec![1, 3, (n + 1)]],
);
for step in recoding_steps {
let shards_to_recode: Vec<_> = shards
.iter()
.cloned()
.enumerate()
.filter_map(|(i, s)| if step.contains(&i) { Some(s) } else { None })
.collect();
shards.push(recode_random(&shards_to_recode, &mut rng).unwrap().unwrap());
}
try_all_decoding_combinations(data, &shards, k, &test_case, None, should_not_be_decodable);
}
#[test]
Loading