use crate::traits::Grow;
#[derive(Debug, Clone)]
pub struct OneWayBoolean {
pub flag: bool,
}
impl Grow for OneWayBoolean {
type Payload = bool;
type Update = ();
type Query = ();
type Value = bool;
fn new(payload: Self::Payload) -> Self {
OneWayBoolean { flag: payload }
}
fn payload(&self) -> Self::Payload {
self.flag
}
fn add(&mut self, _update: Self::Update) {
self.flag = true;
}
fn le(&self, other: &OneWayBoolean) -> bool {
self.flag <= other.flag
}
fn merge(&self, other: &OneWayBoolean) -> Self {
OneWayBoolean {
flag: self.flag || other.flag,
}
}
fn query(&self, _query: &Self::Query) -> Self::Value {
self.flag
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::properties::grow;
use proptest::prelude::*;
fn cvrdt() -> impl Strategy<Value = OneWayBoolean> {
any::<bool>().prop_map(|flag| OneWayBoolean { flag })
}
fn cvrdt_and_update() -> impl Strategy<Value = (OneWayBoolean, ())> {
(cvrdt(), Just(()))
}
grow!(cvrdt, cvrdt_and_update);
}