Skip to main content

hegel/generators/
misc.rs

1use super::{Generator, TestCase};
2
3/// Generate the unit value `()`.
4// nocov start
5pub fn unit() -> JustGenerator<()> {
6    just(())
7    // nocov end
8}
9
10/// Generator that always produces the same value. Created by [`just()`].
11pub struct JustGenerator<T> {
12    value: T,
13}
14
15impl<T: Clone + Send + Sync> Generator<T> for JustGenerator<T> {
16    fn do_draw(&self, _tc: &TestCase) -> T {
17        self.value.clone()
18    }
19}
20
21/// Generate a constant value.
22pub fn just<T: Clone + Send + Sync>(value: T) -> JustGenerator<T> {
23    JustGenerator { value }
24}
25
26/// Generator for boolean values. Created by [`booleans()`].
27pub struct BoolGenerator;
28
29impl Generator<bool> for BoolGenerator {
30    fn do_draw(&self, tc: &TestCase) -> bool {
31        tc.generate_boolean(0.5)
32    }
33}
34
35/// Generate boolean values.
36pub fn booleans() -> BoolGenerator {
37    BoolGenerator
38}