From 6ef17ec32428b498580c57936129aa9207bf08f4 Mon Sep 17 00:00:00 2001 From: Jeff Hemminger Date: Wed, 24 Dec 2025 10:20:34 +0900 Subject: [PATCH] formatted --- src/algorithms/stable_matching/bipartite.rs | 137 ++++++++++++-------- 1 file changed, 82 insertions(+), 55 deletions(-) diff --git a/src/algorithms/stable_matching/bipartite.rs b/src/algorithms/stable_matching/bipartite.rs index cd65d53..0fe9e62 100644 --- a/src/algorithms/stable_matching/bipartite.rs +++ b/src/algorithms/stable_matching/bipartite.rs @@ -155,7 +155,6 @@ where Ok(matches) } - // ============================================================================ // Example Usage and Tests // ============================================================================ @@ -200,40 +199,48 @@ mod tests { // Create bipartite graph with Person nodes let left_partition = HashMap::from([ - (1, Person { - id: 1, - name: "Alice".to_string(), - gender: Gender::Female, - }), - (4, Person { - id: 4, - name: "Bob".to_string(), - gender: Gender::Female, - }), + ( + 1, + Person { + id: 1, + name: "Alice".to_string(), + gender: Gender::Female, + }, + ), + ( + 4, + Person { + id: 4, + name: "Bob".to_string(), + gender: Gender::Female, + }, + ), ]); let right_partition = HashMap::from([ - (2, Person { - id: 2, - name: "Charlie".to_string(), - gender: Gender::Male, - }), - (3, Person { - id: 3, - name: "David".to_string(), - gender: Gender::Male, - }), + ( + 2, + Person { + id: 2, + name: "Charlie".to_string(), + gender: Gender::Male, + }, + ), + ( + 3, + Person { + id: 3, + name: "David".to_string(), + gender: Gender::Male, + }, + ), ]); let graph: BipartiteGraph = BipartiteGraph::new(left_partition, right_partition); // Run stable matching algorithm - let result = stable_match::( - &graph, - &left_prefs, - &right_prefs, - ); + let result = stable_match::(&graph, &left_prefs, &right_prefs); assert!(result.is_ok()); let matches = result.unwrap(); @@ -246,49 +253,69 @@ mod tests { fn test_stable_match_with_string_keys() { // Demonstrate that the algorithm works with different key types let left_prefs: HashMap> = HashMap::from([ - ("alice".to_string(), Preferences::new(vec!["bob".to_string(), "charlie".to_string()])), - ("diana".to_string(), Preferences::new(vec!["charlie".to_string(), "bob".to_string()])), + ( + "alice".to_string(), + Preferences::new(vec!["bob".to_string(), "charlie".to_string()]), + ), + ( + "diana".to_string(), + Preferences::new(vec!["charlie".to_string(), "bob".to_string()]), + ), ]); let right_prefs: HashMap> = HashMap::from([ - ("bob".to_string(), Preferences::new(vec!["alice".to_string(), "diana".to_string()])), - ("charlie".to_string(), Preferences::new(vec!["diana".to_string(), "alice".to_string()])), + ( + "bob".to_string(), + Preferences::new(vec!["alice".to_string(), "diana".to_string()]), + ), + ( + "charlie".to_string(), + Preferences::new(vec!["diana".to_string(), "alice".to_string()]), + ), ]); let left_partition = HashMap::from([ - ("alice".to_string(), Person { - id: 1, - name: "Alice".to_string(), - gender: Gender::Female, - }), - ("diana".to_string(), Person { - id: 2, - name: "Diana".to_string(), - gender: Gender::Female, - }), + ( + "alice".to_string(), + Person { + id: 1, + name: "Alice".to_string(), + gender: Gender::Female, + }, + ), + ( + "diana".to_string(), + Person { + id: 2, + name: "Diana".to_string(), + gender: Gender::Female, + }, + ), ]); let right_partition = HashMap::from([ - ("bob".to_string(), Person { - id: 3, - name: "Bob".to_string(), - gender: Gender::Male, - }), - ("charlie".to_string(), Person { - id: 4, - name: "Charlie".to_string(), - gender: Gender::Male, - }), + ( + "bob".to_string(), + Person { + id: 3, + name: "Bob".to_string(), + gender: Gender::Male, + }, + ), + ( + "charlie".to_string(), + Person { + id: 4, + name: "Charlie".to_string(), + gender: Gender::Male, + }, + ), ]); let graph: BipartiteGraph = BipartiteGraph::new(left_partition, right_partition); - let result = stable_match::( - &graph, - &left_prefs, - &right_prefs, - ); + let result = stable_match::(&graph, &left_prefs, &right_prefs); assert!(result.is_ok()); let matches = result.unwrap(); -- 2.49.1