chore(fhe_strings): add encryption-decryption test

This commit is contained in:
Mayeul@Zama
2024-10-16 17:27:35 +02:00
committed by mayeul-zama
parent b90b20f31e
commit 5056e06380
3 changed files with 22 additions and 0 deletions

View File

@@ -125,6 +125,17 @@ impl Keys {
assert_eq!(dec, expected);
}
pub fn assert_encrypt_decrypt(&self, str: &str, str_pad: Option<u32>) {
let enc_str = FheString::new(&self.ck, str, str_pad);
let dec = self.ck.decrypt_ascii(&enc_str);
println!("\n\x1b[1mEncrypt/Decrypt:\x1b[0m");
result_message(str, str, &dec, Duration::from_nanos(0));
assert_eq!(str, &dec);
}
pub fn assert_contains(
&self,
str: &str,

View File

@@ -140,6 +140,15 @@ fn test_is_empty() {
}
}
#[test]
fn test_encrypt_decrypt() {
let keys = Keys::new();
for (str, str_pad) in TEST_CASES_MATCH {
keys.assert_encrypt_decrypt(str, Some(str_pad));
}
}
#[test]
fn test_contains() {
let keys = Keys::new();

View File

@@ -105,6 +105,8 @@ fn main() {
keys.assert_len(str, str_pad);
keys.assert_is_empty(str, str_pad);
keys.assert_encrypt_decrypt(str, str_pad);
keys.assert_contains(str, str_pad, pat, pat_pad);
keys.assert_ends_with(str, str_pad, pat, pat_pad);
keys.assert_starts_with(str, str_pad, pat, pat_pad);