1mod compatibility;
4pub mod decision_logic;
5pub mod decision_tables;
6mod diagrams;
7mod examples;
8mod exhaustive;
9mod full_model;
10pub mod input_data;
11pub mod item_definition;
12
13pub use compatibility::*;
14pub use diagrams::*;
15pub use examples::valid::*;
16pub use examples::*;
17pub use exhaustive::*;
18pub use full_model::*;
19
20#[cfg(test)]
21mod utilities {
22 use std::collections::BTreeSet;
23 use std::fmt::Write;
24 use walkdir::WalkDir;
25
26 #[test]
28 #[rustfmt::skip]
29 pub fn generate_decision_table_variants() {
30 let mut buffer = String::new();
31 let orientation = ["H", "V", "C"];
32 let information_item = ["0", "1" ];
33 let output_label = ["0", "1" ];
34 let allowed_values = ["0", "1"];
35 let inputs = ["0", "1", "2"];
36 let outputs = ["1", "2"];
37 let annotations = ["0", "1", "2"];
38 let _ = writeln!(&mut buffer, "┌──────┬─────────────┬─────────────┬─────────┬─────────┬──────────┬──────────┬─────────────┬───────────┬────────┐");
39 let _ = writeln!(&mut buffer, "│ No. │ Preferred │ Information │ Output │ Allowed │ Inputs │ Outputs │ Annotations │ Name │ Status │");
40 let _ = writeln!(&mut buffer, "│ │ orientation │ item name │ label │ values │ │ │ │ │ │");
41 let _ = writeln!(&mut buffer, "├──────┼─────────────┼─────────────┼─────────┼─────────┼──────────┼──────────┼─────────────┼───────────┼────────┤");
42 let mut counter = 1;
43 for v_decision_table_orientation in orientation {
44 for v_information_item_name in information_item {
45 for v_output_label in output_label {
46 for v_allowed_values in allowed_values {
47 for v_inputs in inputs {
48 for v_outputs in outputs {
49 for v_annotations in annotations {
50 let dt_name = format!("{}_{}{}{}{}{}{}", v_decision_table_orientation, v_information_item_name, v_output_label, v_allowed_values, v_inputs, v_outputs, v_annotations);
51 let _ = writeln!(&mut buffer, "│ {counter:>4} │{v_decision_table_orientation:^13}│{v_information_item_name:^13}│{v_output_label:^9}│{v_allowed_values:^9}│{v_inputs:^10}│{v_outputs:^10}│{v_annotations:^13}│ {dt_name:9} │ │");
52 counter += 1;
53 }
54 }
55 }
56 }
57 }
58 }
59 }
60 let _ = writeln!(&mut buffer, "└──────┴─────────────┴─────────────┴─────────┴─────────┴──────────┴──────────┴─────────────┴───────────┴────────┘");
61 println!("{}", buffer);
62 assert_eq!(437, buffer.lines().count());
63 }
64
65 #[test]
68 fn compare_the_number_of_models() {
69 let tck_models = count_models("../../tck/TestCases");
70 let tck_adjusted_models = tck_models
71 .iter()
72 .filter_map(|s| {
73 let segments = s.split('/').collect::<Vec<&str>>();
74 let first_segment = segments[0]
75 .replace("compliance-level-2", "level_2")
76 .replace("compliance-level-3", "level_3")
77 .replace("non-compliant", "non_compliant");
78 let last_segment = segments[2][0..4].to_string();
79 if last_segment.chars().next().unwrap().is_ascii_digit() {
80 Some(format!("{}/{}", first_segment, last_segment))
81 } else {
82 None
83 }
84 })
85 .collect::<BTreeSet<String>>();
86
87 let dsntk_models = count_models("src/compatibility");
88 let dsntk_adjusted_models = dsntk_models
89 .iter()
90 .map(|s| {
91 let segments = s.split('/').collect::<Vec<&str>>();
92 let first_segment = segments[0];
93 let last_segment = segments[1][2..6].to_string();
94 format!("{}/{}", first_segment, last_segment)
95 })
96 .collect::<BTreeSet<String>>();
97
98 let mut all_keys = BTreeSet::new();
99 all_keys.append(&mut tck_adjusted_models.clone());
100 all_keys.append(&mut dsntk_adjusted_models.clone());
101
102 println!("────────────────────────────────");
103 println!(" Model TCK DSNTK");
104 println!("────────────────────────────────");
105 for key in &all_keys {
106 println!(
107 "{:20} {:>2} {:>2}",
108 key,
109 if tck_adjusted_models.contains(key) { "OK" } else { "-" },
110 if dsntk_adjusted_models.contains(key) { "OK" } else { "-" }
111 )
112 }
113 }
114
115 fn count_models(root_dir: &str) -> BTreeSet<String> {
117 let mut results = BTreeSet::new();
118 for entry_result in WalkDir::new(root_dir).into_iter() {
119 let entry = entry_result.unwrap();
120 let path = entry.path();
121 if path.is_file() && path.extension().is_some_and(|ext| ext == "dmn") {
122 results.insert(path.strip_prefix(root_dir).unwrap().display().to_string());
123 }
124 }
125 results
126 }
127}