library_tests/
test_share_counts.rs1use wolfram_library_link::{self as wll, DataStore, NumericArray};
2
3#[wll::export]
4fn test_na_automatic_count(array: &NumericArray) -> i64 {
5 array.share_count() as i64
6}
7
8#[wll::export]
9fn test_na_constant_count(array: &NumericArray) -> i64 {
10 array.share_count() as i64
11}
12
13#[wll::export]
14fn test_na_manual_count(array: NumericArray) -> i64 {
15 array.share_count() as i64
16}
17
18#[wll::export]
19fn test_na_shared_count(array: NumericArray) -> i64 {
20 array.share_count() as i64
21}
22
23#[wll::export]
26fn test_na_constant_are_ptr_eq(
27 array1: &NumericArray<i64>,
28 array2: &NumericArray<i64>,
29) -> DataStore {
30 let mut data = DataStore::new();
31 data.add_bool(array1.ptr_eq(&array2));
32 data.add_i64(array1.share_count() as i64);
33 data
34}
35
36#[wll::export]
37fn test_na_manual_are_not_ptr_eq(
38 mut array1: NumericArray<i64>,
39 array2: NumericArray<i64>,
40) -> DataStore {
41 let mut data = DataStore::new();
42 data.add_bool(array1.ptr_eq(&array2));
43 data.add_i64(array1.share_count() as i64);
44 data.add_bool(array1.as_slice_mut().is_some());
45 data
46}
47
48#[wll::export]
49fn test_na_shared_are_ptr_eq(
50 mut array1: NumericArray<i64>,
51 array2: NumericArray<i64>,
52) -> DataStore {
53 let mut data = DataStore::new();
54 data.add_bool(array1.ptr_eq(&array2));
55 data.add_i64(array1.share_count() as i64);
56 data.add_bool(array1.as_slice_mut().is_some());
57 data
58}
59
60#[wll::export]
65fn test_na_clone() -> bool {
66 let array = NumericArray::<i64>::from_slice(&[1, 2, 3]);
67
68 assert!(array.share_count() == 0);
69
70 let clone = array.clone();
71
72 assert!(!array.ptr_eq(&clone));
73
74 assert!(array.share_count() == 0);
75 assert!(clone.share_count() == 0);
76
77 true
78}
79
80#[wll::export]
81fn test_na_shared_clone(array: NumericArray<i64>) -> bool {
82 assert!(array.share_count() == 1);
83
84 let clone = array.clone();
85
86 assert!(!array.ptr_eq(&clone));
87
88 assert!(array.share_count() == 1);
89 assert!(clone.share_count() == 0);
90
91 true
92}