feat(tazjin/german-string): add Eq impl & corresponding proptests

Change-Id: I66a258fad5d4e249268b9d2743d46b30c5ac1dac
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12240
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: tazjin <tazjin@tvl.su>
This commit is contained in:
Vincent Ambo 2024-08-17 01:53:24 +03:00 committed by clbot
parent ab6a4815ff
commit 64a085cf52
3 changed files with 428 additions and 1 deletions

View file

@ -117,6 +117,8 @@ impl PartialEq for GermanString {
}
}
impl Eq for GermanString {}
impl Debug for GermanString {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
String::from_utf8_lossy(self.as_bytes()).fmt(f)
@ -126,6 +128,18 @@ impl Debug for GermanString {
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;
impl Arbitrary for GermanString {
type Parameters = <String as Arbitrary>::Parameters;
type Strategy = BoxedStrategy<Self>;
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
any_with::<String>(args)
.prop_map(|s| GermanString::new_transient(s.as_bytes()))
.boxed()
}
}
#[test]
fn test_empty_string() {
@ -175,4 +189,24 @@ mod tests {
"long string returns correct string"
);
}
// Test [`Eq`] implementation.
proptest! {
#[test]
fn test_reflexivity(x: GermanString) {
prop_assert!(x == x);
}
#[test]
fn test_symmetry(x: GermanString, y: GermanString) {
prop_assert_eq!(x == y, y == x);
}
#[test]
fn test_transitivity(x: GermanString, y: GermanString, z: GermanString) {
if x == y && y == z {
assert!(x == z);
}
}
}
}