#[allow(unused_imports)]
use crate::core::LE;
const fn bool_to_be01(x: bool) -> [u8; 1] {
[x as u8]
}
const fn be01_to_bool(b: [u8; 1]) -> bool {
b[0] != 0
}
crate::conn_l! {
pub BOOLBE01 : bool => [u8; 1] {
ceil: bool_to_be01,
inner: be01_to_bool,
}
}
const fn bool_to_le01(x: bool) -> LE<1> {
LE([x as u8])
}
const fn le01_to_bool(b: LE<1>) -> bool {
b.0[0] != 0
}
crate::conn_l! {
pub BOOLLE01 : bool => LE<1> {
ceil: bool_to_le01,
inner: le01_to_bool,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[allow(unused_imports)]
use crate::conn::ConnL;
use crate::prop::conn as conn_laws;
use proptest::prelude::*;
#[test]
fn bool_le_upper_is_greatest_preimage_with_ceil_below_byte() {
for byte in 0..=u8::MAX {
let b = LE([byte]);
let upper = BOOLLE01.upper(b);
let greatest_preimage = BOOLLE01.ceil(true) <= b;
assert_eq!(upper, byte != 0);
assert_eq!(upper, greatest_preimage);
assert!(BOOLLE01.ceil(upper) <= b);
if !upper {
assert!(BOOLLE01.ceil(true) > b);
}
}
}
fn arb_byte1() -> impl Strategy<Value = [u8; 1]> {
prop_oneof![
Just([0u8]),
Just([u8::MAX]),
Just([0x80u8]),
any::<[u8; 1]>()
]
}
fn arb_lebyte1() -> impl Strategy<Value = LE<1>> {
arb_byte1().prop_map(LE)
}
proptest! {
#[test]
fn bool_be_galois_l(a: bool, b in arb_byte1()) {
prop_assert!(conn_laws::galois_l(&BOOLBE01, a, b));
}
#[test]
fn bool_be_host_roundtrip_l(a: bool) {
prop_assert!(conn_laws::iso_roundtrip_l(&BOOLBE01, a));
}
#[test]
fn bool_be_order_preserving(a: bool, b: bool) {
prop_assert_eq!(a.cmp(&b), BOOLBE01.ceil(a).cmp(&BOOLBE01.ceil(b)));
}
#[test]
fn bool_le_galois_l(a: bool, b in arb_lebyte1()) {
prop_assert!(conn_laws::galois_l(&BOOLLE01, a, b));
}
#[test]
fn bool_le_host_roundtrip_l(a: bool) {
prop_assert!(conn_laws::iso_roundtrip_l(&BOOLLE01, a));
}
#[test]
fn bool_le_kernel_l_for_noncanonical_true_bytes(b in arb_lebyte1().prop_filter("noncanonical true byte", |b| b.0[0] > 1)) {
prop_assert_eq!(BOOLLE01.upper(b), true);
prop_assert_eq!(BOOLLE01.ceil(BOOLLE01.upper(b)), LE([1]));
prop_assert!(conn_laws::kernel_l(&BOOLLE01, b));
prop_assert!(!conn_laws::roundtrip_ceil(&BOOLLE01, b));
}
#[test]
fn bool_le_order_preserving(a: bool, b: bool) {
prop_assert_eq!(a.cmp(&b), BOOLLE01.ceil(a).cmp(&BOOLLE01.ceil(b)));
}
}
}