diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-02-15 17:19:41 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-11-06 16:21:49 +0100 |
commit | 1010d37a2e09984e7bf93541d292f31f5908df04 (patch) | |
tree | f202dd8bd44d5140642377bf3328598a937a3935 | |
parent | bb8e1623e00a3e3b4e13e2adda11ff429770b0e2 (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 cf15bbaa..b9456b2f 100644 --- a/openpgp/src/keyhandle.rs +++ b/openpgp/src/keyhandle.rs @@ -384,8 +384,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, @@ -444,4 +455,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)) + + } + } } |