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