#[cfg(feature = "boolean_ops")]
mod boolean_ops_enabled_tests {
use insign::compile;
#[test]
fn test_boolean_ops_enabled_minus_works() {
let units = vec![
([0, 0, 0], "@a=rc([0,0,0],[4,4,4])".to_string()),
([0, 0, 0], "@b=rc([1,1,1],[3,3,3])".to_string()),
([0, 0, 0], "@result=a-b".to_string()),
];
let result = compile(&units);
assert!(
result.is_ok(),
"Difference operator should work with boolean_ops feature enabled"
);
let dsl_map = result.unwrap();
assert!(dsl_map.contains_key("result"));
let result_entry = dsl_map.get("result").unwrap();
let boxes = result_entry.bounding_boxes.as_ref().unwrap();
assert!(
!boxes.is_empty(),
"Difference should produce at least one bounding box"
);
}
#[test]
fn test_boolean_ops_enabled_and_works() {
let units = vec![
([0, 0, 0], "@a=rc([0,0,0],[4,4,4])".to_string()),
([0, 0, 0], "@b=rc([2,2,2],[6,6,6])".to_string()),
([0, 0, 0], "@result=a&b".to_string()),
];
let result = compile(&units);
assert!(
result.is_ok(),
"Intersection operator should work with boolean_ops feature enabled"
);
let dsl_map = result.unwrap();
assert!(dsl_map.contains_key("result"));
let result_entry = dsl_map.get("result").unwrap();
let boxes = result_entry.bounding_boxes.as_ref().unwrap();
assert_eq!(
boxes.len(),
1,
"Intersection should produce one bounding box"
);
assert_eq!(
boxes[0],
([2, 2, 2], [4, 4, 4]),
"Intersection should be correct"
);
}
#[test]
fn test_boolean_ops_enabled_xor_works() {
let units = vec![
([0, 0, 0], "@a=rc([0,0,0],[3,3,3])".to_string()),
([0, 0, 0], "@b=rc([1,1,1],[4,4,4])".to_string()),
([0, 0, 0], "@result=a^b".to_string()),
];
let result = compile(&units);
assert!(
result.is_ok(),
"XOR operator should work with boolean_ops feature enabled"
);
let dsl_map = result.unwrap();
assert!(dsl_map.contains_key("result"));
let result_entry = dsl_map.get("result").unwrap();
let boxes = result_entry.bounding_boxes.as_ref().unwrap();
assert!(
!boxes.is_empty(),
"XOR should produce at least one bounding box"
);
}
#[test]
fn test_plus_operator_still_works_with_feature() {
let units = vec![
([0, 0, 0], "@a=rc([0,0,0],[1,1,1])".to_string()),
([0, 0, 0], "@b=rc([2,0,0],[3,1,1])".to_string()),
([0, 0, 0], "@result=a+b".to_string()),
];
let result = compile(&units);
assert!(
result.is_ok(),
"Union operator should work with boolean_ops feature enabled"
);
let dsl_map = result.unwrap();
assert!(dsl_map.contains_key("result"));
let result_entry = dsl_map.get("result").unwrap();
let boxes = result_entry.bounding_boxes.as_ref().unwrap();
assert_eq!(boxes.len(), 2, "Union should produce two bounding boxes");
}
}