aboutsummaryrefslogtreecommitdiff
path: root/primrose/crates/primrose-library/src/proptest/strategies.rs
blob: aeb7b0a51bdfc93599c17ec6e4646c50e5443322 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use proptest::prelude::*;
use proptest::strategy::*;
use std::ops::Range;

use crate::eager_sorted_vector::EagerSortedVec;
use crate::eager_unique_vector::EagerUniqueVec;
use crate::lazy_sorted_vector::LazySortedVec;
use crate::lazy_unique_vector::LazyUniqueVec;
use im::conslist::ConsList;
use proptest::collection::vec;
use proptest::prelude::*;

pub fn eager_unique_vec<T: Strategy + 'static>(
    element: T,
    size: Range<usize>,
) -> impl Strategy<Value = EagerUniqueVec<T::Value>>
where
    <T as Strategy>::Value: PartialEq,
{
    vec(element, size.clone()).prop_map(EagerUniqueVec::from_vec)
}

pub fn lazy_unique_vec<T: Strategy + 'static>(
    element: T,
    size: Range<usize>,
) -> impl Strategy<Value = LazyUniqueVec<T::Value>>
where
    <T as Strategy>::Value: Ord,
{
    vec(element, size.clone()).prop_map(LazyUniqueVec::from_vec)
}

pub fn eager_sorted_vec<T: Strategy + 'static>(
    element: T,
    size: Range<usize>,
) -> impl Strategy<Value = EagerSortedVec<T::Value>>
where
    <T as Strategy>::Value: Ord,
{
    vec(element, size.clone()).prop_map(EagerSortedVec::from_vec)
}

pub fn lazy_sorted_vec<T: Strategy + 'static>(
    element: T,
    size: Range<usize>,
) -> impl Strategy<Value = LazySortedVec<T::Value>>
where
    <T as Strategy>::Value: Ord,
{
    vec(element, size.clone()).prop_map(LazySortedVec::from_vec)
}