1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// =============================================================================
// Copyright (c) 2025 - 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
/// Tests for BiConsumer types
use qubit_function::{
ArcBiConsumer,
BiConsumer,
BoxBiConsumer,
RcBiConsumer,
};
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
#[cfg(test)]
mod closure_tests {
use super::{
Arc,
BiConsumer,
};
#[test]
fn test_closure_accept() {
let closure = |x: &i32, y: &i32| {
std::hint::black_box(x + y);
};
closure.accept(&5, &3);
}
#[test]
fn test_closure_and_then() {
let counter = Arc::new(std::sync::Mutex::new(0));
let c1 = counter.clone();
let c2 = counter.clone();
let chained =
qubit_function::BoxBiConsumer::new(move |_x: &i32, _y: &i32| {
*c1.lock().expect("mutex should not be poisoned") += 1;
})
.and_then(move |_x: &i32, _y: &i32| {
*c2.lock().expect("mutex should not be poisoned") += 1;
});
chained.accept(&5, &3);
assert_eq!(*counter.lock().expect("mutex should not be poisoned"), 2);
}
}
// ============================================================================
// Edge Cases Tests
// ============================================================================