diff options
author | Vincent Ambo <mail@tazj.in> | 2024-08-16T22·53+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-08-19T13·19+0000 |
commit | 64a085cf52bbb04effe2846b4a780e37d4ff8408 (patch) | |
tree | 3a3db64a40569ae72da7eca2f3d101b7fdaf3eb1 /users/tazjin/german-string/src/lib.rs | |
parent | ab6a4815ffe84f38bfc0ce5dd5c0a36970009d90 (diff) |
feat(tazjin/german-string): add Eq impl & corresponding proptests r/8530
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>
Diffstat (limited to 'users/tazjin/german-string/src/lib.rs')
-rw-r--r-- | users/tazjin/german-string/src/lib.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/users/tazjin/german-string/src/lib.rs b/users/tazjin/german-string/src/lib.rs index 380ca4ed626c..ed2efd3872f1 100644 --- a/users/tazjin/german-string/src/lib.rs +++ b/users/tazjin/german-string/src/lib.rs @@ -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); + } + } + } } |