Skip to content

Commit

Permalink
Use new proptest integration in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBF committed Aug 20, 2024
1 parent 41b977d commit 35bf0a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 34 deletions.
10 changes: 5 additions & 5 deletions ext/crates/fp/src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod tests {
use crate::{
field::{field_internal::FieldInternal, fp::F2, Fp},
limb,
prime::{tests::arb_prime, Prime, ValidPrime},
prime::{Prime, ValidPrime},
};

pub struct VectorDiffEntry {
Expand Down Expand Up @@ -99,7 +99,7 @@ mod tests {

/// An arbitrary (prime, dimension) pair
fn arb_prime_dim() -> impl Strategy<Value = (ValidPrime, usize)> {
arb_prime().prop_flat_map(|p| (Just(p), 0usize..=10_000))
any::<ValidPrime>().prop_flat_map(|p| (Just(p), 0usize..=10_000))
}

/// The start and end positions of an arbitrary slice of a vector of length `dimension`
Expand Down Expand Up @@ -160,7 +160,7 @@ mod tests {
/// the sense of [`FpVector::add_masked`] and [`FpVector::add_unmasked`])
fn arb_vec_pair_and_mask() -> impl Strategy<Value = (ValidPrime, Vec<u32>, Vec<u32>, Vec<usize>)>
{
arb_prime()
any::<ValidPrime>()
.prop_flat_map(|p| (Just(p), arb_slice(10_000)))
.prop_flat_map(|(p, (dim_small, dim_large))| {
(
Expand All @@ -181,13 +181,13 @@ mod tests {
})]

#[test]
fn test_bit_length(p in arb_prime()) {
fn test_bit_length(p in any::<ValidPrime>()) {
prop_assert!(Fp::new(p).bit_length() <= 63);
}

#[cfg(feature = "odd-primes")]
#[test]
fn test_incompatible_primes((p1, p2) in (arb_prime(), arb_prime())) {
fn test_incompatible_primes((p1, p2) in (any::<ValidPrime>(), any::<ValidPrime>())) {
prop_assume!(p1 != p2);

macro_rules! assert_panic {
Expand Down
30 changes: 1 addition & 29 deletions ext/crates/fp/tests/row_reduce.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
use std::sync::OnceLock;

use fp::{
matrix::Matrix,
prime::{Prime, ValidPrime},
};
use proptest::prelude::*;

/// An arbitrary `ValidPrime` in the range `2..(1 << 24)`, plus the largest prime that we support.
fn arb_prime() -> impl Strategy<Value = ValidPrime> {
static TEST_PRIMES: OnceLock<Vec<ValidPrime>> = OnceLock::new();
let test_primes = TEST_PRIMES.get_or_init(|| {
// Sieve of erathosthenes
const MAX: usize = 1 << 24;
let mut is_prime = Vec::new();
is_prime.resize_with(MAX, || true);
is_prime[0] = false;
is_prime[1] = false;
for i in 2..MAX {
if is_prime[i] {
for j in ((2 * i)..MAX).step_by(i) {
is_prime[j] = false;
}
}
}
(0..MAX)
.filter(|&i| is_prime[i])
.map(|p| ValidPrime::new_unchecked(p as u32))
.chain(std::iter::once(ValidPrime::new_unchecked(2147483647)))
.collect()
});
(0..test_primes.len()).prop_map(|i| test_primes[i])
}

/// An increasing sequence of numbers between 0 and `cols`, where the sequence has a length between
/// 1 and the smaller of `rows` and `cols`. Similar in spirit to a Young tableau / diagram.
///
Expand Down Expand Up @@ -98,7 +70,7 @@ prop_compose! {
/// sequence of row operations, which both depend on those values. The documentation for
/// [`prop_compose`] has more information.
fn arb_reduced_nonreduced_pair()
(p in arb_prime(), rows in 2usize..100, cols in 2usize..100)
(p in any::<ValidPrime>(), rows in 2usize..100, cols in 2usize..100)
(reduced_matrix in arb_rref_matrix(p, rows, cols),
row_ops in arb_coeff_row_pair_seq(p, rows)) -> (Matrix, Matrix)
{
Expand Down

0 comments on commit 35bf0a4

Please sign in to comment.