Skip to content

Commit e29188b

Browse files
author
Test User
committed
test(terraphim_dsm): add missing unit tests for KnowledgeGraph
Add two tests that satisfy the remaining acceptance criteria from #2899: - test_new_creates_empty_graph: explicitly asserts KnowledgeGraph::new() starts with 0 concepts (first AC was unaddressed by the existing 3 tests) - test_group_by_concept_buckets_modules: verifies group_by_concept correctly partitions matched vs uncategorized modules cargo test -p terraphim_dsm now reports 5 passed / 0 failed. Refs #2899
1 parent 61b5e37 commit e29188b

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

crates/terraphim_dsm/src/knowledge.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ mod tests {
187187
use std::io::Write;
188188
use tempfile::TempDir;
189189

190+
#[test]
191+
fn test_new_creates_empty_graph() {
192+
let temp_dir = TempDir::new().unwrap();
193+
let kg = KnowledgeGraph::new(temp_dir.path().to_path_buf());
194+
assert_eq!(kg.concept_count(), 0);
195+
}
196+
190197
#[test]
191198
fn test_knowledge_graph_loading() {
192199
let temp_dir = TempDir::new().unwrap();
@@ -257,4 +264,36 @@ mod tests {
257264
assert!(kg.are_related("auth_module", "security_handler"));
258265
assert!(!kg.are_related("auth_module", "ui_component"));
259266
}
267+
268+
#[test]
269+
fn test_group_by_concept_buckets_modules() {
270+
let temp_dir = TempDir::new().unwrap();
271+
let kg_dir = temp_dir.path().join("kg");
272+
std::fs::create_dir(&kg_dir).unwrap();
273+
274+
let mut auth_file = std::fs::File::create(kg_dir.join("Authentication.md")).unwrap();
275+
writeln!(auth_file, "# Authentication").unwrap();
276+
writeln!(auth_file, "synonyms:: auth, login").unwrap();
277+
278+
let mut kg = KnowledgeGraph::new(kg_dir.clone());
279+
kg.load_from_directory(&kg_dir).unwrap();
280+
281+
let modules = vec![
282+
"service::auth_handler".to_string(),
283+
"service::login_manager".to_string(),
284+
"service::unrelated_utils".to_string(),
285+
];
286+
let groups = kg.group_by_concept(&modules);
287+
288+
assert!(
289+
groups.contains_key("Authentication"),
290+
"auth modules must be grouped"
291+
);
292+
assert_eq!(groups["Authentication"].len(), 2);
293+
assert!(
294+
groups.contains_key("uncategorized"),
295+
"unmatched modules go to uncategorized"
296+
);
297+
assert_eq!(groups["uncategorized"].len(), 1);
298+
}
260299
}

0 commit comments

Comments
 (0)