superinstance_ffi/
holonomy.rs1#[no_mangle]
6pub extern "C" fn si_holonomy_check(transforms: *const i64, len: usize) -> bool {
7 if transforms.is_null() || len == 0 {
8 return true; }
10 let slice = unsafe { std::slice::from_raw_parts(transforms, len) };
11 let product: i64 = slice.iter().product();
12 product == 1
13}
14
15#[cfg(test)]
16mod tests {
17 use super::*;
18
19 #[test]
20 fn test_holonomy_trivial() {
21 assert!(si_holonomy_check(std::ptr::null(), 0));
22 }
23
24 #[test]
25 fn test_holonomy_identity() {
26 let transforms: [i64; 3] = [1, 1, 1];
27 assert!(si_holonomy_check(transforms.as_ptr(), 3));
28 }
29
30 #[test]
31 fn test_holonomy_product_one() {
32 let transforms: [i64; 3] = [-1, -1, 1];
34 assert!(si_holonomy_check(transforms.as_ptr(), 3));
35 }
36
37 #[test]
38 fn test_holonomy_fail() {
39 let transforms: [i64; 2] = [2, 3]; assert!(!si_holonomy_check(transforms.as_ptr(), 2));
41 }
42}