Skip to content

Commit

Permalink
add test for right bit shift with assignment (#703)
Browse files Browse the repository at this point in the history
* add test for bit shift right with assignment

* fixed comment

Co-authored-by: Martina <martina@martina>
  • Loading branch information
martinacantaro and Martina committed Jan 11, 2023
1 parent 1eb5735 commit 23536dc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions felt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,17 @@ mod test {
prop_assert!(as_uint < p, "{}", as_uint);
prop_assert_eq!(&(q * y), x);
}

#[test]
// Property-based test that ensures, for 100 {value}s that are randomly generated each time tests are run, that performing a bit shift to the right by {shift_amount} of bits (between 0 and 999), with assignment, returns a result that is inside of the range [0, p].
// "With assignment" means that the result of the operation is autommatically assigned to the variable value, replacing its previous content.
fn shift_right_assign_in_range(ref value in "(0|[1-9][0-9]*)", ref shift_amount in "[0-9]{1,3}"){
let mut value = Felt::parse_bytes(value.as_bytes(), 10).unwrap();
let p = FeltBigInt::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap();
let shift_amount:usize = shift_amount.parse::<usize>().unwrap();
value >>= shift_amount;
value.to_biguint();
prop_assert!(value < p);
}
}
}

0 comments on commit 23536dc

Please sign in to comment.