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
// =============================================================================
// Copyright (c) 2025 - 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
// ============================================================================
// BoxTransformer Tests - Immutable, single ownership
// ============================================================================
#[cfg(test)]
mod trait_usage_tests {
use qubit_function::{
BoxTransformer,
Transformer,
};
#[test]
fn test_transformer_trait() {
fn apply_transformer<F: Transformer<i32, i32>>(f: &F, x: i32) -> i32 {
f.apply(x)
}
let double = BoxTransformer::new(|x: i32| x * 2);
assert_eq!(apply_transformer(&double, 21), 42);
}
#[test]
fn test_closure_as_transformer() {
fn apply_transformer<F: Transformer<i32, i32>>(f: &F, x: i32) -> i32 {
f.apply(x)
}
let double = |x: i32| x * 2;
assert_eq!(apply_transformer(&double, 21), 42);
}
#[test]
fn test_with_different_types() {
fn apply_transformer<T, R, F: Transformer<T, R>>(f: &F, x: T) -> R {
f.apply(x)
}
let to_string = BoxTransformer::new(|x: i32| x.to_string());
assert_eq!(apply_transformer(&to_string, 42), "42");
}
}
// ============================================================================
// Complex Composition Tests
// ============================================================================