diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-02-15 17:19:41 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2024-01-25 11:58:21 +0100 |
commit | 276aab39514c51d68b41b898631deb53ecf96bd4 (patch) | |
tree | 6907a39aa1750fb85d1e6674e2c6947a88bb4711 | |
parent | 9916ecd436f5d8c4a892e2c6250eb15ced465814 (diff) |
openpgp: Implement Arbitrary for KeyHandle, add tests.
-rw-r--r-- | openpgp/src/keyhandle.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/openpgp/src/keyhandle.rs b/openpgp/src/keyhandle.rs index 63d7666b..a667979e 100644 --- a/openpgp/src/keyhandle.rs +++ b/openpgp/src/keyhandle.rs @@ -401,8 +401,19 @@ impl KeyHandle { #[cfg(test)] mod tests { + use quickcheck::{Arbitrary, Gen}; use super::*; + impl Arbitrary for KeyHandle { + fn arbitrary(g: &mut Gen) -> Self { + if bool::arbitrary(g) { + Fingerprint::arbitrary(g).into() + } else { + KeyID::arbitrary(g).into() + } + } + } + #[test] fn upper_hex_formatting() { let handle = KeyHandle::Fingerprint(Fingerprint::V4([1, 2, 3, 4, 5, 6, 7, @@ -461,4 +472,34 @@ mod tests { Ok(()) } + + quickcheck! { + fn partial_cmp_is_asymmetric(a: KeyHandle, b: KeyHandle) + -> bool { + use Ordering::*; + true + && (! (a.partial_cmp(&b) == Some(Less)) + || ! (a.partial_cmp(&b) == Some(Greater))) + && (! (a.partial_cmp(&b) == Some(Greater)) + || ! (a.partial_cmp(&b) == Some(Less))) + } + } + + quickcheck! { + fn partial_cmp_is_transitive(a: KeyHandle, b: KeyHandle, c: KeyHandle) + -> bool { + use Ordering::*; + true + && (! (a.partial_cmp(&b) == Some(Less) + && b.partial_cmp(&c) == Some(Less)) + || a.partial_cmp(&c) == Some(Less)) + && (! (a.partial_cmp(&b) == Some(Equal) + && b.partial_cmp(&c) == Some(Equal)) + || a.partial_cmp(&c) == Some(Equal)) + && (! (a.partial_cmp(&b) == Some(Greater) + && b.partial_cmp(&c) == Some(Greater)) + || a.partial_cmp(&c) == Some(Greater)) + + } + } } |