use ifc_schema::{ifc2x3, ifc4, ifc4x3, Schema};
fn bundled() -> [(&'static str, &'static Schema); 3] {
[("IFC2X3", ifc2x3()), ("IFC4", ifc4()), ("IFC4X3", ifc4x3())]
}
#[test]
fn subtypes_is_the_inverse_of_is_a_on_every_bundled_schema() {
for (label, schema) in bundled() {
let names: Vec<&str> = schema.entity_names().collect();
for &ancestor in &names {
let down: std::collections::HashSet<&str> =
schema.subtypes(ancestor).into_iter().collect();
for &candidate in &names {
let expected = candidate != ancestor && schema.is_a(candidate, ancestor);
assert_eq!(
down.contains(candidate),
expected,
"{label}: {candidate} under {ancestor}"
);
}
}
}
}
#[test]
fn every_element_includes_walls_doors_and_their_subtypes() {
for (label, schema) in bundled() {
let elements = schema.subtypes("IfcElement");
for expected in ["IfcWall", "IfcWallStandardCase", "IfcDoor", "IfcBeam"] {
assert!(
elements
.iter()
.any(|name| name.eq_ignore_ascii_case(expected)),
"{label}: {expected} must be an IfcElement"
);
}
assert!(
!elements
.iter()
.any(|name| name.eq_ignore_ascii_case("IfcProject")),
"{label}: IfcProject is not an element"
);
}
}
#[test]
fn the_answer_depends_on_the_schema_version() {
assert!(ifc4x3()
.direct_subtypes("IfcElement")
.contains(&"IfcBuiltElement"));
assert!(!ifc4()
.direct_subtypes("IfcElement")
.contains(&"IfcBuiltElement"));
}
#[test]
fn an_undeclared_name_has_no_subtypes() {
assert!(ifc4().subtypes("IfcNotAThing").is_empty());
}