use qubit_function::{
ArcBiFunction,
ArcBiPredicate,
BiFunction,
BiFunctionOnce,
BoxBiFunction,
FnBiFunctionOps,
RcBiFunction,
RcBiPredicate,
};
#[test]
fn test_bi_function_trait_apply() {
let add = |x: &i32, y: &i32| *x + *y;
assert_eq!(add.apply(&20, &22), 42);
assert_eq!(add.apply(&0, &0), 0);
assert_eq!(add.apply(&-10, &5), -5);
}
#[test]
fn test_bi_function_trait_into_box() {
let add = |x: &i32, y: &i32| *x + *y;
let boxed = BiFunction::into_box(add);
assert_eq!(boxed.apply(&20, &22), 42);
}
#[test]
fn test_bi_function_trait_into_rc() {
let add = |x: &i32, y: &i32| *x + *y;
let rc = add.into_rc();
assert_eq!(rc.apply(&20, &22), 42);
}
#[test]
fn test_bi_function_trait_into_arc() {
let add = |x: &i32, y: &i32| *x + *y;
let arc = add.into_arc();
assert_eq!(arc.apply(&20, &22), 42);
}
#[test]
fn test_bi_function_trait_into_fn() {
let add = |x: &i32, y: &i32| *x + *y;
let func = BiFunction::into_fn(add);
assert_eq!(func(&20, &22), 42);
}
#[test]
fn test_bi_function_trait_into_once() {
let add = |x: &i32, y: &i32| *x + *y;
let once = add.into_once();
assert_eq!(once.apply(&20, &22), 42);
}
#[test]
fn test_custom_bi_function_default_methods() {
#[derive(Debug)]
struct CustomBiFunction {
multiplier: i32,
}
impl BiFunction<i32, i32, i32> for CustomBiFunction {
fn apply(&self, first: &i32, second: &i32) -> i32 {
first * second * self.multiplier
}
}
let custom_func = CustomBiFunction { multiplier: 3 };
let boxed = custom_func.into_box();
assert_eq!(boxed.apply(&2, &4), 24); }
#[test]
fn test_cloneable_bi_function_default_methods() {
#[derive(Clone, Debug)]
struct CloneableBiFunction {
multiplier: i32,
}
impl BiFunction<i32, i32, i32> for CloneableBiFunction {
fn apply(&self, first: &i32, second: &i32) -> i32 {
first * second * self.multiplier
}
}
let custom_func = CloneableBiFunction { multiplier: 2 };
let boxed = custom_func.to_box();
assert_eq!(boxed.apply(&3, &5), 30);
let rc_func = custom_func.to_rc();
assert_eq!(rc_func.apply(&3, &5), 30);
let func = custom_func.to_fn();
assert_eq!(func(&3, &5), 30);
let once = custom_func.to_once();
assert_eq!(once.apply(&3, &5), 30);
}
#[test]
fn test_thread_safe_bi_function_default_methods() {
#[derive(Clone, Debug)]
struct ThreadSafeBiFunction {
multiplier: i32,
}
impl BiFunction<i32, i32, i32> for ThreadSafeBiFunction {
fn apply(&self, first: &i32, second: &i32) -> i32 {
first * second * self.multiplier
}
}
let custom_func = ThreadSafeBiFunction { multiplier: 4 };
let arc_func = custom_func.to_arc();
assert_eq!(arc_func.apply(&2, &3), 24);
let arc_func2 = custom_func.into_arc();
assert_eq!(arc_func2.apply(&2, &3), 24);
}
#[test]
fn test_box_bi_function_new() {
let add = BoxBiFunction::new(|x: &i32, y: &i32| *x + *y);
assert_eq!(add.apply(&10, &15), 25);
}
#[test]
fn test_box_bi_function_new_allows_non_static_t() {
fn run<'a>(value: &'a str) -> usize {
let func: BoxBiFunction<&'a str, i32, usize> =
BoxBiFunction::new(|x: &&'a str, y: &i32| x.len() + (*y as usize));
func.apply(&value, &3)
}
let text = String::from("hello");
assert_eq!(run(text.as_str()), 8);
}
#[test]
fn test_box_bi_function_new_allows_non_static_u() {
fn run<'a>(value: &'a str) -> usize {
let func: BoxBiFunction<i32, &'a str, usize> =
BoxBiFunction::new(|x: &i32, y: &&'a str| (*x as usize) + y.len());
func.apply(&3, &value)
}
let text = String::from("world");
assert_eq!(run(text.as_str()), 8);
}
#[test]
fn test_box_bi_function_new_allows_non_static_r() {
fn run<'a>(value: &'a str) -> &'a str {
let func: BoxBiFunction<&'a str, i32, &'a str> =
BoxBiFunction::new(|x: &&'a str, _y: &i32| *x);
func.apply(&value, &0)
}
let text = String::from("qubit");
assert_eq!(run(text.as_str()), "qubit");
}
#[test]
fn test_box_bi_function_constant() {
let constant = BoxBiFunction::constant(42);
assert_eq!(constant.apply(&1, &2), 42);
assert_eq!(constant.apply(&100, &200), 42);
}
#[test]
fn test_box_bi_function_debug_display() {
let func = BoxBiFunction::new(|x: &i32, y: &i32| *x + *y);
let debug_str = format!("{:?}", func);
assert!(debug_str.contains("BoxBiFunction"));
let display_str = format!("{}", func);
assert!(display_str.starts_with("BoxBiFunction"));
}
#[test]
fn test_rc_bi_function_new() {
let multiply = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
assert_eq!(multiply.apply(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_new_allows_non_static_t() {
fn run<'a>(value: &'a str) -> usize {
let func: RcBiFunction<&'a str, i32, usize> =
RcBiFunction::new(|x: &&'a str, y: &i32| x.len() + (*y as usize));
func.apply(&value, &3)
}
let text = String::from("hello");
assert_eq!(run(text.as_str()), 8);
}
#[test]
fn test_rc_bi_function_new_allows_non_static_u() {
fn run<'a>(value: &'a str) -> usize {
let func: RcBiFunction<i32, &'a str, usize> =
RcBiFunction::new(|x: &i32, y: &&'a str| (*x as usize) + y.len());
func.apply(&3, &value)
}
let text = String::from("world");
assert_eq!(run(text.as_str()), 8);
}
#[test]
fn test_rc_bi_function_new_allows_non_static_r() {
fn run<'a>(value: &'a str) -> &'a str {
let func: RcBiFunction<&'a str, i32, &'a str> =
RcBiFunction::new(|x: &&'a str, _y: &i32| *x);
func.apply(&value, &0)
}
let text = String::from("qubit");
assert_eq!(run(text.as_str()), "qubit");
}
#[test]
fn test_rc_bi_function_constant() {
let constant = RcBiFunction::constant(100);
assert_eq!(constant.apply(&1, &2), 100);
}
#[test]
fn test_rc_bi_function_clone() {
let original = RcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let cloned = original.clone();
assert_eq!(original.apply(&10, &20), 30);
assert_eq!(cloned.apply(&10, &20), 30);
}
#[test]
fn test_rc_bi_function_debug_display() {
let func = RcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let debug_str = format!("{:?}", func);
assert!(debug_str.contains("RcBiFunction"));
let display_str = format!("{}", func);
assert!(display_str.starts_with("RcBiFunction"));
}
#[test]
fn test_rc_bi_function_and_then() {
use qubit_function::RcFunction;
let add = RcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let multiply_by_two = RcFunction::new(|x: &i32| *x * 2);
let chained = add.and_then(multiply_by_two);
assert_eq!(chained.apply(&2, &3), 10); }
#[test]
fn test_arc_bi_function_new() {
let divide = ArcBiFunction::new(|x: &i32, y: &i32| *x / *y);
assert_eq!(divide.apply(&42, &2), 21);
}
#[test]
fn test_arc_bi_function_new_allows_non_static_t() {
fn run<'a>(value: &'a str) -> usize {
let func: ArcBiFunction<&'a str, i32, usize> =
ArcBiFunction::new(|x: &&'a str, y: &i32| x.len() + (*y as usize));
func.apply(&value, &3)
}
let text = String::from("hello");
assert_eq!(run(text.as_str()), 8);
}
#[test]
fn test_arc_bi_function_new_allows_non_static_u() {
fn run<'a>(value: &'a str) -> usize {
let func: ArcBiFunction<i32, &'a str, usize> =
ArcBiFunction::new(|x: &i32, y: &&'a str| (*x as usize) + y.len());
func.apply(&3, &value)
}
let text = String::from("world");
assert_eq!(run(text.as_str()), 8);
}
#[test]
fn test_arc_bi_function_new_allows_non_static_r() {
fn run<'a>(value: &'a str) -> &'a str {
let func: ArcBiFunction<&'a str, i32, &'a str> =
ArcBiFunction::new(|x: &&'a str, _y: &i32| *x);
func.apply(&value, &0)
}
let text = String::from("qubit");
assert_eq!(run(text.as_str()), "qubit");
}
#[test]
fn test_arc_bi_function_constant() {
let constant = ArcBiFunction::constant("hello".to_string());
assert_eq!(constant.apply(&1, &2), "hello");
}
#[test]
fn test_arc_bi_function_clone() {
let original = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let cloned = original.clone();
assert_eq!(original.apply(&50, &8), 42);
assert_eq!(cloned.apply(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_debug_display() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let debug_str = format!("{:?}", func);
assert!(debug_str.contains("ArcBiFunction"));
let display_str = format!("{}", func);
assert!(display_str.starts_with("ArcBiFunction"));
}
#[test]
fn test_bi_function_conversions() {
let add = |x: &i32, y: &i32| *x + *y;
let boxed = BiFunction::to_box(&add);
assert_eq!(boxed.apply(&10, &20), 30);
let rc = BiFunction::to_rc(&add);
assert_eq!(rc.apply(&10, &20), 30);
let arc = BiFunction::to_arc(&add);
assert_eq!(arc.apply(&10, &20), 30);
let func = BiFunction::to_fn(&add);
assert_eq!(func(&10, &20), 30);
let once = add.to_once();
assert_eq!(once.apply(&10, &20), 30);
}
#[test]
fn test_bi_function_and_then() {
use qubit_function::FnBiFunctionOps;
let add = |x: &i32, y: &i32| *x + *y;
let double = |x: &i32| *x * 2;
let composed = add.and_then(double);
assert_eq!(composed.apply(&10, &15), 50); }
#[test]
fn test_bi_function_when_or_else() {
use qubit_function::FnBiFunctionOps;
let add = |x: &i32, y: &i32| *x + *y;
let multiply = |x: &i32, y: &i32| *x * *y;
let conditional = add
.when(|x: &i32, y: &i32| *x > 0 && *y > 0)
.or_else(multiply);
assert_eq!(conditional.apply(&5, &3), 8); assert_eq!(conditional.apply(&-5, &3), -15); }
#[test]
fn test_bi_function_with_complex_types() {
let concat = |s1: &&str, s2: &&str| format!("{} {}", *s1, *s2);
let boxed = BoxBiFunction::new(concat);
assert_eq!(boxed.apply(&"Hello", &"World"), "Hello World");
}
#[test]
fn test_bi_function_with_option_types() {
let combine_options = |opt1: &Option<i32>, opt2: &Option<i32>| match (opt1, opt2) {
(Some(a), Some(b)) => Some(a + b),
_ => None,
};
let func = RcBiFunction::new(combine_options);
assert_eq!(func.apply(&Some(10), &Some(20)), Some(30));
assert_eq!(func.apply(&Some(10), &None), None);
assert_eq!(func.apply(&None, &Some(20)), None);
}
#[test]
fn test_bi_function_with_result_types() {
let safe_divide = |a: &i32, b: &i32| {
if *b == 0 {
Err("Division by zero")
} else {
Ok(*a / *b)
}
};
let func = ArcBiFunction::new(safe_divide);
assert_eq!(func.apply(&10, &2), Ok(5));
assert_eq!(func.apply(&10, &0), Err("Division by zero"));
}
#[test]
fn test_box_bi_function_new_with_name() {
let func = BoxBiFunction::new_with_name("adder", |x: &i32, y: &i32| *x + *y);
assert_eq!(func.name(), Some("adder"));
assert_eq!(func.apply(&10, &20), 30);
}
#[test]
fn test_box_bi_function_new_with_optional_name() {
let func1 = BoxBiFunction::new_with_optional_name(
|x: &i32, y: &i32| *x + *y,
Some("named".to_string()),
);
let func2 = BoxBiFunction::new_with_optional_name(|x: &i32, y: &i32| *x + *y, None);
assert_eq!(func1.name(), Some("named"));
assert_eq!(func2.name(), None);
assert_eq!(func1.apply(&5, &7), 12);
assert_eq!(func2.apply(&5, &7), 12);
}
#[test]
fn test_box_bi_function_name_and_set_name() {
let mut func = BoxBiFunction::new(|x: &i32, y: &i32| *x + *y);
assert_eq!(func.name(), None);
func.set_name("test_func");
assert_eq!(func.name(), Some("test_func"));
func.set_name("updated_name");
assert_eq!(func.name(), Some("updated_name"));
}
#[test]
fn test_box_bi_function_into_box() {
let func = BoxBiFunction::new(|x: &i32, y: &i32| *x + *y);
let boxed = func.into_box();
assert_eq!(boxed.apply(&1, &2), 3);
}
#[test]
fn test_box_bi_function_into_rc() {
let func = BoxBiFunction::new(|x: &i32, y: &i32| *x + *y);
let rc = func.into_rc();
assert_eq!(rc.apply(&1, &2), 3);
}
#[test]
fn test_rc_bi_function_new_with_name() {
let func = RcBiFunction::new_with_name("multiplier", |x: &i32, y: &i32| *x * *y);
assert_eq!(func.name(), Some("multiplier"));
assert_eq!(func.apply(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_new_with_optional_name() {
let func1 =
RcBiFunction::new_with_optional_name(|x: &i32, y: &i32| *x * *y, Some("named".to_string()));
let func2 = RcBiFunction::new_with_optional_name(|x: &i32, y: &i32| *x * *y, None);
assert_eq!(func1.name(), Some("named"));
assert_eq!(func2.name(), None);
assert_eq!(func1.apply(&6, &7), 42);
assert_eq!(func2.apply(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_name_and_set_name() {
let mut func = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
assert_eq!(func.name(), None);
func.set_name("test_func");
assert_eq!(func.name(), Some("test_func"));
}
#[test]
fn test_rc_bi_function_into_box() {
let func = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let boxed = func.into_box();
assert_eq!(boxed.apply(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_into_rc() {
let func = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let rc = func.into_rc();
assert_eq!(rc.apply(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_into_fn() {
let func = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let closure = func.into_fn();
assert_eq!(closure(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_into_once() {
let func = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let once = func.into_once();
assert_eq!(once.apply(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_to_box() {
let func = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let boxed = func.to_box();
assert_eq!(boxed.apply(&6, &7), 42);
assert_eq!(func.apply(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_to_rc() {
let func = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let rc = func.to_rc();
assert_eq!(rc.apply(&6, &7), 42);
assert_eq!(func.apply(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_to_fn() {
let func = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let closure = func.to_fn();
assert_eq!(closure(&6, &7), 42);
assert_eq!(func.apply(&6, &7), 42);
}
#[test]
fn test_rc_bi_function_to_once() {
let func = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let once = func.to_once();
assert_eq!(once.apply(&6, &7), 42);
assert_eq!(func.apply(&6, &7), 42);
}
#[test]
fn test_arc_bi_function_new_with_name() {
let func = ArcBiFunction::new_with_name("divider", |x: &i32, y: &i32| *x / *y);
assert_eq!(func.name(), Some("divider"));
assert_eq!(func.apply(&42, &2), 21);
}
#[test]
fn test_arc_bi_function_new_with_optional_name() {
let func1 = ArcBiFunction::new_with_optional_name(
|x: &i32, y: &i32| *x / *y,
Some("named".to_string()),
);
let func2 = ArcBiFunction::new_with_optional_name(|x: &i32, y: &i32| *x / *y, None);
assert_eq!(func1.name(), Some("named"));
assert_eq!(func2.name(), None);
assert_eq!(func1.apply(&42, &2), 21);
assert_eq!(func2.apply(&42, &2), 21);
}
#[test]
fn test_arc_bi_function_name_and_set_name() {
let mut func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
assert_eq!(func.name(), None);
func.set_name("test_func");
assert_eq!(func.name(), Some("test_func"));
}
#[test]
fn test_arc_bi_function_into_box() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let boxed = func.into_box();
assert_eq!(boxed.apply(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_into_rc() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let rc = func.into_rc();
assert_eq!(rc.apply(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_into_arc() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let arc = func.into_arc();
assert_eq!(arc.apply(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_into_fn() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let closure = func.into_fn();
assert_eq!(closure(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_into_once() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let once = func.into_once();
assert_eq!(once.apply(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_to_box() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let boxed = func.to_box();
assert_eq!(boxed.apply(&50, &8), 42);
assert_eq!(func.apply(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_to_rc() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let rc = func.to_rc();
assert_eq!(rc.apply(&50, &8), 42);
assert_eq!(func.apply(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_to_arc() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let arc = func.to_arc();
assert_eq!(arc.apply(&50, &8), 42);
assert_eq!(func.apply(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_to_fn() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let closure = func.to_fn();
assert_eq!(closure(&50, &8), 42);
assert_eq!(func.apply(&50, &8), 42);
}
#[test]
fn test_arc_bi_function_to_once() {
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let once = func.to_once();
assert_eq!(once.apply(&50, &8), 42);
assert_eq!(func.apply(&50, &8), 42);
}
#[test]
fn test_box_conditional_bi_function_when_or_else() {
let add = BoxBiFunction::new(|x: &i32, y: &i32| *x + *y);
let multiply = BoxBiFunction::new(|x: &i32, y: &i32| *x * *y);
let conditional = add
.when(|x: &i32, y: &i32| *x > 0 && *y > 0)
.or_else(multiply);
assert_eq!(conditional.apply(&3, &4), 7); assert_eq!(conditional.apply(&-3, &4), -12); }
#[test]
fn test_rc_conditional_bi_function_when_or_else() {
let add = RcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let multiply = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let conditional = add
.when(|x: &i32, y: &i32| *x > 0 && *y > 0)
.or_else(multiply);
assert_eq!(conditional.apply(&3, &4), 7); assert_eq!(conditional.apply(&-3, &4), -12); }
#[test]
fn test_arc_conditional_bi_function_when_or_else() {
let add = ArcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let multiply = ArcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let conditional = add
.when(|x: &i32, y: &i32| *x > 0 && *y > 0)
.or_else(multiply);
assert_eq!(conditional.apply(&3, &4), 7); assert_eq!(conditional.apply(&-3, &4), -12); }
#[test]
fn test_conditional_bi_function_with_complex_predicates() {
let add = BoxBiFunction::new(|x: &i32, y: &i32| *x + *y);
let subtract = BoxBiFunction::new(|x: &i32, y: &i32| *x - *y);
let conditional = add.when(|x: &i32, y: &i32| *x >= *y).or_else(subtract);
assert_eq!(conditional.apply(&5, &3), 8); assert_eq!(conditional.apply(&3, &5), -2); }
#[test]
fn test_conditional_bi_function_display_debug() {
let add = BoxBiFunction::new(|x: &i32, y: &i32| *x + *y);
let conditional = add.when(|x: &i32, _y: &i32| *x > 0);
let display = format!("{}", conditional);
assert!(display.contains("BoxConditionalBiFunction"));
let debug = format!("{:?}", conditional);
assert!(debug.contains("BoxConditionalBiFunction"));
}
#[test]
fn test_rc_conditional_bi_function_clone() {
let add = RcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let multiply = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let conditional = add
.when(|x: &i32, y: &i32| *x > 0 && *y > 0)
.or_else(multiply);
let cloned = conditional.clone();
assert_eq!(conditional.apply(&3, &4), 7); assert_eq!(conditional.apply(&-3, &4), -12);
assert_eq!(cloned.apply(&3, &4), 7); assert_eq!(cloned.apply(&-3, &4), -12); }
#[test]
fn test_arc_conditional_bi_function_clone() {
let add = ArcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let multiply = ArcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let conditional = add
.when(|x: &i32, y: &i32| *x > 0 && *y > 0)
.or_else(multiply);
let cloned = conditional.clone();
assert_eq!(conditional.apply(&3, &4), 7); assert_eq!(conditional.apply(&-3, &4), -12);
assert_eq!(cloned.apply(&3, &4), 7); assert_eq!(cloned.apply(&-3, &4), -12); }
#[test]
fn test_impl_conditional_function_clone_three_params_macro_coverage() {
println!("Starting test_impl_conditional_function_clone_three_params_macro_coverage");
{
println!("Testing RcConditionalBiFunction with macro-generated Clone (three parameters)");
let add = RcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let pred = RcBiPredicate::new(|x: &i32, y: &i32| *x > 0 && *y > 0);
let conditional_rc = add.when(pred);
println!("Calling clone() on RcConditionalBiFunction - this should trigger macro-generated three-param code");
let cloned_rc = conditional_rc.clone();
println!("Clone completed for RcConditionalBiFunction");
let multiply = RcBiFunction::new(|x: &i32, y: &i32| *x * *y);
let func = cloned_rc.or_else(multiply);
assert_eq!(func.apply(&3, &4), 7); assert_eq!(func.apply(&-3, &4), -12); println!("RcConditionalBiFunction test passed");
}
{
println!("Testing ArcConditionalBiFunction with macro-generated Clone (three parameters)");
let subtract = ArcBiFunction::new(|x: &i32, y: &i32| *x - *y);
let pred = ArcBiPredicate::new(|x: &i32, y: &i32| *x >= *y);
let conditional_arc = subtract.when(pred);
println!("Calling clone() on ArcConditionalBiFunction - this should trigger macro-generated three-param code");
let cloned_arc = conditional_arc.clone();
println!("Clone completed for ArcConditionalBiFunction");
let negate = ArcBiFunction::new(|x: &i32, y: &i32| -*x - *y);
let func = cloned_arc.or_else(negate);
assert_eq!(func.apply(&5, &3), 2); assert_eq!(func.apply(&3, &5), -8); println!("ArcConditionalBiFunction test passed");
}
println!("Three-parameter conditional clone macro test passed!");
}
#[test]
fn test_bi_function_complex_composition() {
let add = |x: &i32, y: &i32| *x + *y;
let multiply_by_two = |x: &i32| *x * 2;
let to_string = |x: &i32| x.to_string();
let composed = add.and_then(multiply_by_two).and_then(to_string);
assert_eq!(composed.apply(&3, &4), "14"); }
#[test]
fn test_bi_function_conditional_composition() {
let add = |x: &i32, y: &i32| *x + *y;
let multiply = |x: &i32, y: &i32| *x * *y;
let square = |x: &i32| *x * *x;
let conditional = add
.when(|x: &i32, y: &i32| *x > 0 && *y > 0)
.or_else(multiply)
.and_then(square);
assert_eq!(conditional.apply(&3, &4), 49); assert_eq!(conditional.apply(&-3, &4), 144); }
#[test]
fn test_arc_bi_function_and_then() {
use qubit_function::ArcFunction;
let add = ArcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let multiply_by_two = ArcFunction::new(|x: &i32| *x * 2);
let chained = add.and_then(multiply_by_two);
assert_eq!(chained.apply(&2, &3), 10); }
#[test]
fn test_arc_bi_function_thread_safety() {
use std::thread;
let func = ArcBiFunction::new(|x: &i32, y: &i32| *x + *y);
let func_clone = func.clone();
let handle = thread::spawn(move || func_clone.apply(&10, &20));
let result = handle.join().unwrap();
assert_eq!(result, 30);
assert_eq!(func.apply(&10, &20), 30);
}