diff --git a/tfhe/src/strings/test_functions/test_common.rs b/tfhe/src/strings/test_functions/test_common.rs index 17330d7db..7c82b2e88 100644 --- a/tfhe/src/strings/test_functions/test_common.rs +++ b/tfhe/src/strings/test_functions/test_common.rs @@ -43,14 +43,11 @@ where P: Into, { let executor = CpuFunctionExecutor::new(&ServerKey::is_empty); - string_is_empty_test_impl(param, executor, |a| a.is_empty()); + string_is_empty_test_impl(param, executor); } -pub(crate) fn string_is_empty_test_impl( - param: P, - mut is_empty_executor: T, - clear_function: for<'a> fn(&'a str) -> bool, -) where +pub(crate) fn string_is_empty_test_impl(param: P, mut is_empty_executor: T) +where P: Into, T: for<'a> FunctionExecutor<&'a FheString, FheStringIsEmpty>, { @@ -63,7 +60,7 @@ pub(crate) fn string_is_empty_test_impl( // trivial for str in ["", "a", "abc"] { for pad in 0..3 { - let expected_result = clear_function(str); + let expected_result = str.is_empty(); let enc_str = FheString::new_trivial(&cks, str, Some(pad)); @@ -82,7 +79,7 @@ pub(crate) fn string_is_empty_test_impl( let pad = 1; for str in ["", "abc"] { - let expected_result = clear_function(str); + let expected_result = str.is_empty(); let enc_str = FheString::new(&cks, str, Some(pad)); @@ -109,14 +106,11 @@ where P: Into, { let executor = CpuFunctionExecutor::new(&ServerKey::len); - string_len_test_impl(param, executor, |a| a.len()); + string_len_test_impl(param, executor); } -pub(crate) fn string_len_test_impl( - param: P, - mut len_executor: T, - clear_function: for<'a> fn(&'a str) -> usize, -) where +pub(crate) fn string_len_test_impl(param: P, mut len_executor: T) +where P: Into, T: for<'a> FunctionExecutor<&'a FheString, FheStringLen>, { @@ -129,7 +123,7 @@ pub(crate) fn string_len_test_impl( // trivial for str in ["", "a", "abc"] { for pad in 0..3 { - let expected_result = clear_function(str); + let expected_result = str.len(); let enc_str = FheString::new_trivial(&cks, str, Some(pad)); @@ -150,7 +144,7 @@ pub(crate) fn string_len_test_impl( let pad = 1; for str in ["", "abc"] { - let expected_result = clear_function(str); + let expected_result = str.len(); let enc_str = FheString::new(&cks, str, Some(pad)); diff --git a/tfhe/src/strings/test_functions/test_concat.rs b/tfhe/src/strings/test_functions/test_concat.rs index e89dab23b..6dc325b1b 100644 --- a/tfhe/src/strings/test_functions/test_concat.rs +++ b/tfhe/src/strings/test_functions/test_concat.rs @@ -20,14 +20,11 @@ where P: Into, { let executor = CpuFunctionExecutor::new(&ServerKey::concat); - string_concat_test_impl(param, executor, |lhs, rhs| lhs.to_owned() + rhs); + string_concat_test_impl(param, executor); } -pub(crate) fn string_concat_test_impl( - param: P, - mut concat_executor: T, - clear_function: for<'a> fn(&'a str, &'a str) -> String, -) where +pub(crate) fn string_concat_test_impl(param: P, mut concat_executor: T) +where P: Into, T: for<'a> FunctionExecutor<(&'a FheString, &'a FheString), FheString>, { @@ -42,7 +39,7 @@ pub(crate) fn string_concat_test_impl( for rhs_pad in 0..2 { for str in TEST_CASES_CONCAT { for rhs in TEST_CASES_CONCAT { - let expected_result = clear_function(str, rhs); + let expected_result = str.to_owned() + rhs; let enc_lhs = FheString::new_trivial(&cks, str, Some(str_pad)); let enc_rhs = FheString::new_trivial(&cks, rhs, Some(rhs_pad)); @@ -61,7 +58,7 @@ pub(crate) fn string_concat_test_impl( let rhs = "b"; let rhs_pad = 1; - let expected_result = clear_function(str, rhs); + let expected_result = str.to_owned() + rhs; let enc_lhs = FheString::new(&cks, str, Some(str_pad)); let enc_rhs = FheString::new(&cks, rhs, Some(rhs_pad)); @@ -83,14 +80,11 @@ where P: Into, { let executor = CpuFunctionExecutor::new(&ServerKey::repeat); - string_repeat_test_impl(param, executor, |lhs, n| lhs.repeat(n as usize)); + string_repeat_test_impl(param, executor); } -pub(crate) fn string_repeat_test_impl( - param: P, - mut repeat_executor: T, - clear_function: for<'a> fn(&'a str, u16) -> String, -) where +pub(crate) fn string_repeat_test_impl(param: P, mut repeat_executor: T) +where P: Into, T: for<'a> FunctionExecutor<(&'a FheString, &'a UIntArg), FheString>, { @@ -105,7 +99,7 @@ pub(crate) fn string_repeat_test_impl( for n in 0..3 { for str in TEST_CASES_CONCAT { for max in n..n + 2 { - let expected_result = clear_function(str, n); + let expected_result = str.repeat(n as usize); let enc_str = FheString::new_trivial(&cks, str, Some(str_pad)); @@ -129,7 +123,7 @@ pub(crate) fn string_repeat_test_impl( let n = 1; let max = 2; - let expected_result = clear_function(str, n); + let expected_result = str.repeat(n as usize); let enc_str = FheString::new(&cks, str, Some(str_pad)); diff --git a/tfhe/src/strings/test_functions/test_find_replace.rs b/tfhe/src/strings/test_functions/test_find_replace.rs index 74915f71c..9cf60c55e 100644 --- a/tfhe/src/strings/test_functions/test_find_replace.rs +++ b/tfhe/src/strings/test_functions/test_find_replace.rs @@ -121,14 +121,11 @@ where P: Into, { let executor = CpuFunctionExecutor::new(&ServerKey::replace); - string_replace_test_impl(param, executor, |str, from, to| str.replace(from, to)); + string_replace_test_impl(param, executor); } -pub(crate) fn string_replace_test_impl( - param: P, - mut replace_executor: T, - clear_function: for<'a> fn(&'a str, &'a str, &'a str) -> String, -) where +pub(crate) fn string_replace_test_impl(param: P, mut replace_executor: T) +where P: Into, T: for<'a> FunctionExecutor<(&'a FheString, GenericPatternRef<'a>, &'a FheString), FheString>, { @@ -145,7 +142,7 @@ pub(crate) fn string_replace_test_impl( for str in TEST_CASES_FIND { for from in PATTERN_FIND { for to in ["", " ", "a", "abc"] { - let expected_result = clear_function(str, from, to); + let expected_result = str.replace(from, to); let enc_str = FheString::new_trivial(&cks, str, Some(str_pad)); let enc_from = GenericPattern::Enc(FheString::new_trivial( @@ -181,7 +178,7 @@ pub(crate) fn string_replace_test_impl( let to_pad = 1; for from in ["a", "c"] { - let expected_result = clear_function(str, from, to); + let expected_result = str.replace(from, to); let enc_str = FheString::new_trivial(&cks, str, Some(str_pad)); let enc_from = GenericPattern::Enc(FheString::new_trivial(&cks, from, Some(from_pad))); @@ -211,16 +208,11 @@ where P: Into, { let executor = CpuFunctionExecutor::new(&ServerKey::replacen); - string_replacen_test_impl(param, executor, |str, from, to, count| { - str.replacen(from, to, count as usize) - }); + string_replacen_test_impl(param, executor); } -pub(crate) fn string_replacen_test_impl( - param: P, - mut replacen_executor: T, - clear_function: for<'a> fn(&'a str, &'a str, &'a str, u16) -> String, -) where +pub(crate) fn string_replacen_test_impl(param: P, mut replacen_executor: T) +where P: Into, T: for<'a> FunctionExecutor< ( @@ -247,7 +239,7 @@ pub(crate) fn string_replacen_test_impl( for to in ["", " ", "a", "abc"] { for n in 0..=2 { for max in n..n + 2 { - let expected_result = clear_function(str, from, to, n); + let expected_result = str.replacen(from, to, n as usize); let enc_str = FheString::new_trivial(&cks, str, Some(str_pad)); let enc_from = GenericPattern::Enc(FheString::new_trivial( @@ -296,7 +288,7 @@ pub(crate) fn string_replacen_test_impl( let max = 2; for from in ["a", "c"] { - let expected_result = clear_function(str, from, to, n); + let expected_result = str.replacen(from, to, n as usize); let enc_str = FheString::new_trivial(&cks, str, Some(str_pad)); let enc_from = GenericPattern::Enc(FheString::new_trivial(&cks, from, Some(from_pad))); diff --git a/tfhe/src/strings/test_functions/test_up_low_case.rs b/tfhe/src/strings/test_functions/test_up_low_case.rs index bc0409799..bf886a30b 100644 --- a/tfhe/src/strings/test_functions/test_up_low_case.rs +++ b/tfhe/src/strings/test_functions/test_up_low_case.rs @@ -97,14 +97,11 @@ where P: Into, { let executor = CpuFunctionExecutor::new(&ServerKey::eq_ignore_case); - string_eq_ignore_case_test_impl(param, executor, |lhs, rhs| lhs.eq_ignore_ascii_case(rhs)); + string_eq_ignore_case_test_impl(param, executor); } -pub(crate) fn string_eq_ignore_case_test_impl( - param: P, - mut eq_ignore_case_executor: T, - clear_function: for<'a> fn(&'a str, &'a str) -> bool, -) where +pub(crate) fn string_eq_ignore_case_test_impl(param: P, mut eq_ignore_case_executor: T) +where P: Into, T: for<'a> FunctionExecutor<(&'a FheString, GenericPatternRef<'a>), BooleanBlock>, { @@ -119,7 +116,7 @@ pub(crate) fn string_eq_ignore_case_test_impl( for rhs_pad in 0..2 { for str in UP_LOW_CASE { for rhs in UP_LOW_CASE { - let expected_result = clear_function(str, rhs); + let expected_result = str.eq_ignore_ascii_case(rhs); let enc_str = FheString::new(&cks, str, Some(str_pad)); @@ -143,7 +140,7 @@ pub(crate) fn string_eq_ignore_case_test_impl( let rhs_pad = 1; for rhs in ["Ab", "Ac"] { - let expected_result = clear_function(str, rhs); + let expected_result = str.eq_ignore_ascii_case(rhs); let enc_str = FheString::new(&cks, str, Some(str_pad)); let enc_rhs = GenericPattern::Enc(FheString::new_trivial(&cks, rhs, Some(rhs_pad))); diff --git a/tfhe/src/strings/test_functions/test_whitespace.rs b/tfhe/src/strings/test_functions/test_whitespace.rs index c9df76bb1..8ea470b7e 100644 --- a/tfhe/src/strings/test_functions/test_whitespace.rs +++ b/tfhe/src/strings/test_functions/test_whitespace.rs @@ -106,17 +106,11 @@ where let executor = CpuFunctionExecutor::new(&fhe_func); - let func: for<'a> fn(&'a str) -> Box + 'a> = - |lhs| Box::new(lhs.split_ascii_whitespace()); - - string_split_whitespace_test_impl(param, executor, func); + string_split_whitespace_test_impl(param, executor); } -pub(crate) fn string_split_whitespace_test_impl( - param: P, - mut split_whitespace_executor: T, - clear_function: for<'a> fn(&'a str) -> Box + 'a>, -) where +pub(crate) fn string_split_whitespace_test_impl(param: P, mut split_whitespace_executor: T) +where P: Into, T: for<'a> FunctionExecutor<&'a FheString, Box>, { @@ -145,7 +139,11 @@ pub(crate) fn string_split_whitespace_test_impl( format!("{ws}a{ws}a"), format!("a{ws}a{ws}a"), ] { - let expected: Vec<_> = clear_function(&str).map(Some).chain(once(None)).collect(); + let expected: Vec<_> = str + .split_ascii_whitespace() + .map(Some) + .chain(once(None)) + .collect(); let enc_str = FheString::new(&cks, &str, Some(str_pad)); @@ -170,7 +168,11 @@ pub(crate) fn string_split_whitespace_test_impl( let str_pad = 1; for str in ["a b", "abc"] { - let expected: Vec<_> = clear_function(str).map(Some).chain(once(None)).collect(); + let expected: Vec<_> = str + .split_ascii_whitespace() + .map(Some) + .chain(once(None)) + .collect(); let enc_str = FheString::new(&cks, str, Some(str_pad));