Skip to content

Commit

Permalink
chore(strings): use trivial in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Oct 28, 2024
1 parent b99ceff commit de17046
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions tfhe/src/strings/assert_functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Keys {
pub fn assert_len(&self, str: &str, str_pad: Option<u32>) {
let expected = str.len();

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

let start = Instant::now();
let result = self.sk.len(&enc_str);
Expand All @@ -107,7 +107,7 @@ impl Keys {
pub fn assert_is_empty(&self, str: &str, str_pad: Option<u32>) {
let expected = str.is_empty();

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

let start = Instant::now();
let result = self.sk.is_empty(&enc_str);
Expand All @@ -125,7 +125,7 @@ impl Keys {
}

pub fn assert_encrypt_decrypt(&self, str: &str, str_pad: Option<u32>) {
let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

let dec = self.ck.decrypt_ascii(&enc_str);

Expand All @@ -144,8 +144,8 @@ impl Keys {
) {
let expected = str.contains(pat);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));
let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string()));

let start = Instant::now();
Expand Down Expand Up @@ -180,8 +180,8 @@ impl Keys {
) {
let expected = str.ends_with(pat);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));
let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string()));

let start = Instant::now();
Expand Down Expand Up @@ -216,8 +216,8 @@ impl Keys {
) {
let expected = str.starts_with(pat);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));
let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string()));

let start = Instant::now();
Expand Down Expand Up @@ -246,8 +246,8 @@ impl Keys {
pub fn assert_find(&self, str: &str, str_pad: Option<u32>, pat: &str, pat_pad: Option<u32>) {
let expected = str.find(pat);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));
let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string()));

let start = Instant::now();
Expand Down Expand Up @@ -282,8 +282,8 @@ impl Keys {
pub fn assert_rfind(&self, str: &str, str_pad: Option<u32>, pat: &str, pat_pad: Option<u32>) {
let expected = str.rfind(pat);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));
let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string()));

let start = Instant::now();
Expand Down Expand Up @@ -324,8 +324,8 @@ impl Keys {
) {
let expected = str.strip_prefix(pat);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));
let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string()));

let start = Instant::now();
Expand Down Expand Up @@ -374,8 +374,8 @@ impl Keys {
) {
let expected = str.strip_suffix(pat);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));
let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string()));

let start = Instant::now();
Expand Down Expand Up @@ -424,8 +424,8 @@ impl Keys {
) {
let expected = str.eq_ignore_ascii_case(rhs);

let enc_lhs = FheString::new(&self.ck, str, str_pad);
let enc_rhs = GenericPattern::Enc(FheString::new(&self.ck, rhs, rhs_pad));
let enc_lhs = FheString::new_trivial(&self.ck, str, str_pad);
let enc_rhs = GenericPattern::Enc(FheString::new_trivial(&self.ck, rhs, rhs_pad));
let clear_rhs = GenericPattern::Clear(ClearString::new(rhs.to_string()));

let start = Instant::now();
Expand All @@ -452,8 +452,8 @@ impl Keys {
}

pub fn assert_comp(&self, str: &str, str_pad: Option<u32>, rhs: &str, rhs_pad: Option<u32>) {
let enc_lhs = FheString::new(&self.ck, str, str_pad);
let enc_rhs = GenericPattern::Enc(FheString::new(&self.ck, rhs, rhs_pad));
let enc_lhs = FheString::new_trivial(&self.ck, str, str_pad);
let enc_rhs = GenericPattern::Enc(FheString::new_trivial(&self.ck, rhs, rhs_pad));
let clear_rhs = GenericPattern::Clear(ClearString::new(rhs.to_string()));

// Equal
Expand Down Expand Up @@ -504,7 +504,7 @@ impl Keys {
result_message_clear_rhs(str, rhs, expected_ne, dec_ne, end.duration_since(start));
assert_eq!(dec_ne, expected_ne);

let enc_rhs = FheString::new(&self.ck, rhs, rhs_pad);
let enc_rhs = FheString::new_trivial(&self.ck, rhs, rhs_pad);

// Greater or equal
let expected_ge = str >= rhs;
Expand Down Expand Up @@ -562,7 +562,7 @@ impl Keys {
pub fn assert_to_lowercase(&self, str: &str, str_pad: Option<u32>) {
let expected = str.to_lowercase();

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

let start = Instant::now();
let result = self.sk.to_lowercase(&enc_str);
Expand All @@ -579,7 +579,7 @@ impl Keys {
pub fn assert_to_uppercase(&self, str: &str, str_pad: Option<u32>) {
let expected = str.to_uppercase();

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

let start = Instant::now();
let result = self.sk.to_uppercase(&enc_str);
Expand All @@ -596,8 +596,8 @@ impl Keys {
pub fn assert_concat(&self, str: &str, str_pad: Option<u32>, rhs: &str, rhs_pad: Option<u32>) {
let expected = str.to_owned() + rhs;

let enc_lhs = FheString::new(&self.ck, str, str_pad);
let enc_rhs = FheString::new(&self.ck, rhs, rhs_pad);
let enc_lhs = FheString::new_trivial(&self.ck, str, str_pad);
let enc_rhs = FheString::new_trivial(&self.ck, rhs, rhs_pad);

let start = Instant::now();
let result = self.sk.concat(&enc_lhs, &enc_rhs);
Expand All @@ -614,7 +614,7 @@ impl Keys {
pub fn assert_repeat(&self, str: &str, str_pad: Option<u32>, n: u16, max: u16) {
let expected = str.repeat(n as usize);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

// Clear n
let start = Instant::now();
Expand All @@ -641,7 +641,7 @@ impl Keys {
assert_eq!(dec, expected);

// Encrypted n
let enc_n = self.ck.encrypt_u16(n, Some(max));
let enc_n = self.ck.trivial_encrypt_u16(n, Some(max));

let start = Instant::now();
let result = self.sk.repeat(&enc_str, &UIntArg::Enc(enc_n));
Expand Down Expand Up @@ -670,7 +670,7 @@ impl Keys {
pub fn assert_trim_end(&self, str: &str, str_pad: Option<u32>) {
let expected = str.trim_end();

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

let start = Instant::now();
let result = self.sk.trim_end(&enc_str);
Expand All @@ -687,7 +687,7 @@ impl Keys {
pub fn assert_trim_start(&self, str: &str, str_pad: Option<u32>) {
let expected = str.trim_start();

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

let start = Instant::now();
let result = self.sk.trim_start(&enc_str);
Expand All @@ -704,7 +704,7 @@ impl Keys {
pub fn assert_trim(&self, str: &str, str_pad: Option<u32>) {
let expected = str.trim();

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

let start = Instant::now();
let result = self.sk.trim(&enc_str);
Expand All @@ -722,7 +722,7 @@ impl Keys {
let mut expected: Vec<_> = str.split_ascii_whitespace().map(Some).collect();
expected.push(None);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);

let mut results = Vec::with_capacity(expected.len());

Expand Down Expand Up @@ -769,8 +769,8 @@ impl Keys {
) {
let expected = str.split_once(pat);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));

let start = Instant::now();
let (lhs, rhs, is_some) = self.sk.split_once(&enc_str, &enc_pat);
Expand All @@ -797,8 +797,8 @@ impl Keys {
) {
let expected = str.rsplit_once(pat);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));

let start = Instant::now();
let (lhs, rhs, is_some) = self.sk.rsplit_once(&enc_str, &enc_pat);
Expand All @@ -820,8 +820,8 @@ impl Keys {
let mut expected: Vec<_> = str.split(pat).map(Some).collect();
expected.push(None);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));

let mut results = Vec::with_capacity(expected.len());

Expand Down Expand Up @@ -858,8 +858,8 @@ impl Keys {
let mut expected: Vec<_> = str.rsplit(pat).map(Some).collect();
expected.push(None);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));

let mut results = Vec::with_capacity(expected.len());

Expand Down Expand Up @@ -902,8 +902,8 @@ impl Keys {
let mut expected: Vec<_> = str.split_terminator(pat).map(Some).collect();
expected.push(None);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));

let mut results = Vec::with_capacity(expected.len());

Expand Down Expand Up @@ -946,8 +946,8 @@ impl Keys {
let mut expected: Vec<_> = str.rsplit_terminator(pat).map(Some).collect();
expected.push(None);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));

let mut results = Vec::with_capacity(expected.len());

Expand Down Expand Up @@ -990,8 +990,8 @@ impl Keys {
let mut expected: Vec<_> = str.split_inclusive(pat).map(Some).collect();
expected.push(None);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));

let mut results = Vec::with_capacity(expected.len());

Expand Down Expand Up @@ -1036,8 +1036,8 @@ impl Keys {
let mut expected: Vec<_> = str.splitn(n as usize, pat).map(Some).collect();
expected.push(None);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));

let mut results = Vec::with_capacity(expected.len());

Expand Down Expand Up @@ -1084,7 +1084,7 @@ impl Keys {

assert_eq!(dec_as_str, expected);

let enc_n = self.ck.encrypt_u16(n, Some(max));
let enc_n = self.ck.trivial_encrypt_u16(n, Some(max));
results.clear();

// Call next enough times
Expand Down Expand Up @@ -1143,8 +1143,8 @@ impl Keys {
let mut expected: Vec<_> = str.rsplitn(n as usize, pat).map(Some).collect();
expected.push(None);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));

let mut results = Vec::with_capacity(expected.len());

Expand Down Expand Up @@ -1191,7 +1191,7 @@ impl Keys {

assert_eq!(dec_as_str, expected);

let enc_n = self.ck.encrypt_u16(n, Some(max));
let enc_n = self.ck.trivial_encrypt_u16(n, Some(max));
results.clear();

// Call next enough times
Expand Down Expand Up @@ -1249,10 +1249,10 @@ impl Keys {
) {
let expected = str.replace(pat, to);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));
let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string()));
let enc_to = FheString::new(&self.ck, to, to_pad);
let enc_to = FheString::new_trivial(&self.ck, to, to_pad);

let start = Instant::now();
let result = self.sk.replace(&enc_str, &enc_pat, &enc_to);
Expand Down Expand Up @@ -1321,13 +1321,13 @@ impl Keys {

let expected = str.replacen(pat, to, n as usize);

let enc_str = FheString::new(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new(&self.ck, pat, pat_pad));
let enc_str = FheString::new_trivial(&self.ck, str, str_pad);
let enc_pat = GenericPattern::Enc(FheString::new_trivial(&self.ck, pat, pat_pad));
let clear_pat = GenericPattern::Clear(ClearString::new(pat.to_string()));
let enc_to = FheString::new(&self.ck, to, to_pad);
let enc_to = FheString::new_trivial(&self.ck, to, to_pad);

let clear_n = UIntArg::Clear(n);
let enc_n = UIntArg::Enc(self.ck.encrypt_u16(n, Some(max)));
let enc_n = UIntArg::Enc(self.ck.trivial_encrypt_u16(n, Some(max)));

let start = Instant::now();
let result = self.sk.replacen(&enc_str, &enc_pat, &enc_to, &clear_n);
Expand Down

0 comments on commit de17046

Please sign in to comment.