This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathcompose.rs
64 lines (55 loc) · 1.84 KB
/
compose.rs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2020 The Propverify authors
// Based on parts of Proptest which is Copyright 2017, 2018 Jason Lingle
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
////////////////////////////////////////////////////////////////
// Proptest-based tests exploring how to use prop_compose
////////////////////////////////////////////////////////////////
#[cfg(not(verify))]
use proptest::prelude::*;
#[cfg(verify)]
use propverify::prelude::*;
#[cfg(test)]
mod test {
use super::*;
use core::fmt::Debug;
#[derive(Clone, Debug)]
struct MyStruct {
x: u32,
y: u32,
}
// First version - written by hand
fn my_struct_strategy1(max_integer: u32) -> impl Strategy<Value = MyStruct> {
let strat = (0..max_integer, 0..max_integer);
Strategy::prop_map(strat, move |(x, y)| MyStruct { x, y })
}
proptest! {
#[test]
fn struct_test1(s in my_struct_strategy1(10)) {
assert!(s.x < 10);
assert!(s.y < 10);
}
}
// identical to my_struct_strategy1 but written using prop_compose!
prop_compose! {
fn my_struct_strategy2(max_integer: u32)
(x in 0..max_integer, y in 0..max_integer)
-> MyStruct {
MyStruct { x, y, }
}
}
proptest! {
#[test]
fn struct_test2(s in my_struct_strategy2(10)) {
assert!(s.x < 10);
assert!(s.y < 10);
}
}
}
////////////////////////////////////////////////////////////////
// End
////////////////////////////////////////////////////////////////