test: use proptest factor to switch proptest mode

This commit is contained in:
Zixuan Chen 2022-10-17 15:28:07 +08:00
parent 9d66aeb511
commit d47fe2df8c
8 changed files with 44 additions and 41 deletions

View file

@ -23,15 +23,16 @@ fn basic() {
assert_eq!(*container.get_value(), LoroValue::Map(ans));
}
#[cfg(not(no_proptest))]
mod map_proptest {
use crate::tests::PROPTEST_FACTOR_10;
use super::*;
proptest! {
#[test]
fn insert(
key in prop::collection::vec("[a-z]", 0..22),
value in prop::collection::vec(gen_insert_value(), 0..22)
key in prop::collection::vec("[a-z]", 0..10 * PROPTEST_FACTOR_10),
value in prop::collection::vec(gen_insert_value(), 0..10 * PROPTEST_FACTOR_10)
) {
let mut loro = LoroCore::default();
let accessor = loro.store.get_accessor();

View file

@ -519,11 +519,10 @@ mod find_common_ancestors {
}
}
#[cfg(not(no_proptest))]
mod find_common_ancestors_proptest {
use proptest::prelude::*;
use crate::{array_mut_ref, unsafe_array_mut_ref};
use crate::{array_mut_ref, tests::PROPTEST_FACTOR_10, unsafe_array_mut_ref};
use super::*;
@ -545,69 +544,53 @@ mod find_common_ancestors_proptest {
proptest! {
#[test]
fn test_2dags(
before_merged_insertions in prop::collection::vec(gen_interaction(2), 0..100),
after_merged_insertions in prop::collection::vec(gen_interaction(2), 0..100)
before_merged_insertions in prop::collection::vec(gen_interaction(2), 0..100 * PROPTEST_FACTOR_10),
after_merged_insertions in prop::collection::vec(gen_interaction(2), 0..100 * PROPTEST_FACTOR_10)
) {
test_single_common_ancestor(2, before_merged_insertions, after_merged_insertions)?;
}
#[test]
fn test_4dags(
before_merged_insertions in prop::collection::vec(gen_interaction(4), 0..100),
after_merged_insertions in prop::collection::vec(gen_interaction(4), 0..100)
before_merged_insertions in prop::collection::vec(gen_interaction(4), 0..100 * PROPTEST_FACTOR_10),
after_merged_insertions in prop::collection::vec(gen_interaction(4), 0..100 * PROPTEST_FACTOR_10)
) {
test_single_common_ancestor(4, before_merged_insertions, after_merged_insertions)?;
}
#[test]
fn test_10dags(
before_merged_insertions in prop::collection::vec(gen_interaction(10), 0..100),
after_merged_insertions in prop::collection::vec(gen_interaction(10), 0..100)
before_merged_insertions in prop::collection::vec(gen_interaction(10), 0..10 * PROPTEST_FACTOR_10 * PROPTEST_FACTOR_10),
after_merged_insertions in prop::collection::vec(gen_interaction(10), 0..10 * PROPTEST_FACTOR_10 * PROPTEST_FACTOR_10)
) {
test_single_common_ancestor(10, before_merged_insertions, after_merged_insertions)?;
}
#[test]
fn test_mul_ancestors_5dags(
before_merged_insertions in prop::collection::vec(gen_interaction(10), 0..100),
after_merged_insertions in prop::collection::vec(gen_interaction(10), 0..100)
before_merged_insertions in prop::collection::vec(gen_interaction(10), 0..100 * PROPTEST_FACTOR_10),
after_merged_insertions in prop::collection::vec(gen_interaction(10), 0..100 * PROPTEST_FACTOR_10)
) {
test_mul_ancestors::<2>(5, before_merged_insertions, after_merged_insertions)?;
}
#[test]
fn test_mul_ancestors_10dags(
before_merged_insertions in prop::collection::vec(gen_interaction(10), 0..100),
after_merged_insertions in prop::collection::vec(gen_interaction(10), 0..100)
before_merged_insertions in prop::collection::vec(gen_interaction(10), 0..10 * PROPTEST_FACTOR_10 * PROPTEST_FACTOR_10),
after_merged_insertions in prop::collection::vec(gen_interaction(10), 0..10 * PROPTEST_FACTOR_10 * PROPTEST_FACTOR_10)
) {
test_mul_ancestors::<3>(10, before_merged_insertions, after_merged_insertions)?;
}
#[test]
fn test_mul_ancestors_15dags_2(
before_merged_insertions in prop::collection::vec(gen_interaction(15), 0..50),
after_merged_insertions in prop::collection::vec(gen_interaction(15), 0..50)
before_merged_insertions in prop::collection::vec(gen_interaction(15), 0..10 * PROPTEST_FACTOR_10 * PROPTEST_FACTOR_10),
after_merged_insertions in prop::collection::vec(gen_interaction(15), 0..10 * PROPTEST_FACTOR_10 * PROPTEST_FACTOR_10)
) {
test_mul_ancestors::<5>(15, before_merged_insertions, after_merged_insertions)?;
}
}
#[test]
fn issue() {
if let Err(err) = test_mul_ancestors::<3>(
10,
vec![Interaction {
dag_idx: 2,
merge_with: Some(5),
len: 1,
}],
vec![],
) {
println!("{}", err);
panic!();
}
}
fn preprocess(interactions: &mut [Interaction], num: i32) {
for interaction in interactions.iter_mut() {
interaction.dag_idx %= num as usize;

View file

@ -21,7 +21,7 @@ mod smstring;
mod snapshot;
mod span;
#[cfg(test)]
mod tests;
pub mod tests;
mod value;
pub(crate) mod macros;

View file

@ -1 +1,6 @@
#![cfg(test)]
#[cfg(feature = "fuzzing")]
pub const PROPTEST_FACTOR_10: usize = 10;
#[cfg(not(feature = "fuzzing"))]
pub const PROPTEST_FACTOR_10: usize = 1;

View file

@ -30,3 +30,5 @@ pub use crate::rle_vec::{RleVec, SearchResult, SliceIterator};
pub mod rle_impl;
pub use rle_tree::tree_trait::RleTreeTrait;
pub use rle_tree::RleTree;
#[cfg(test)]
mod test;

View file

@ -334,15 +334,16 @@ fn issue_5() {
])
}
#[cfg(not(no_proptest))]
mod notify_proptest {
use crate::test::PROPTEST_FACTOR_10;
use super::*;
use proptest::prelude::*;
proptest! {
#[test]
fn test_notify(
interactions in prop::collection::vec(gen_interaction(), 1..100),
interactions in prop::collection::vec(gen_interaction(), 1..20 * PROPTEST_FACTOR_10* PROPTEST_FACTOR_10),
) {
test(&interactions);
}

View file

@ -86,7 +86,7 @@ fn basic_string_op() {
fn issue_0() {
let mut tree: RleTree<CustomString, StringTreeTrait> = RleTree::default();
let insert_keys = "0123456789abcdefghijklmnopq";
for i in 0..(1e5 as usize) {
for i in 0..(1e4 as usize * crate::test::PROPTEST_FACTOR_10) {
let start = i % insert_keys.len();
if i % 3 == 0 && tree.len() > 0 {
let start = i % tree.len();
@ -290,8 +290,9 @@ fn issue_delete() {
])
}
#[cfg(not(no_proptest))]
mod string_proptest {
use crate::test::{PROPTEST_FACTOR_1, PROPTEST_FACTOR_10};
use super::*;
use proptest::prelude::*;
@ -319,17 +320,16 @@ mod string_proptest {
proptest! {
#[test]
fn test_tree_string_op_the_same(
interactions in prop::collection::vec(gen_interaction(), 1..50),
interactions in prop::collection::vec(gen_interaction(), 1..20 * PROPTEST_FACTOR_10 + PROPTEST_FACTOR_1 * 1000),
) {
run_test(interactions);
}
}
#[cfg(slow_proptest)]
proptest! {
#[test]
fn test_tree_string_op_the_same_slow(
interactions in prop::collection::vec(gen_interaction(), 1..2000),
interactions in prop::collection::vec(gen_interaction(), 1..20 * PROPTEST_FACTOR_10 + PROPTEST_FACTOR_1 * 1000),
) {
let mut s = String::new();
let mut tree = RleTree::default();

11
crates/rle/src/test.rs Normal file
View file

@ -0,0 +1,11 @@
#![cfg(test)]
#[cfg(feature = "fuzzing")]
pub const PROPTEST_FACTOR_10: usize = 10;
#[cfg(not(feature = "fuzzing"))]
pub const PROPTEST_FACTOR_10: usize = 1;
#[cfg(feature = "fuzzing")]
pub const PROPTEST_FACTOR_1: usize = 1;
#[cfg(not(feature = "fuzzing"))]
pub const PROPTEST_FACTOR_1: usize = 0;