From 8238d3d0a8e62a42cc309819d8f6655aa7c4cb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 23 Feb 2025 18:20:42 +0100 Subject: [PATCH] fix: create all permutations of depth for tree command --- src/tag_engine.rs | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/tag_engine.rs b/src/tag_engine.rs index 89503ff..b9bee0e 100644 --- a/src/tag_engine.rs +++ b/src/tag_engine.rs @@ -95,14 +95,12 @@ pub fn create_tag_combinations(tags: &[String], depth: usize) -> Vec // Start with existing combinations of length-1 for combo in result.iter().filter(|c| c.len() == len - 1) { - // Try to add each remaining tag that comes after the last tag in combo - if let Some(last) = combo.last() { - for tag in tags { - if tag > last && !combo.contains(tag) { - let mut new_combo = combo.clone(); - new_combo.push(tag.clone()); - temp.push(new_combo); - } + // Try to add each remaining tag + for tag in tags { + if !combo.contains(tag) { + let mut new_combo = combo.clone(); + new_combo.push(tag.clone()); + temp.push(new_combo); } } } @@ -322,20 +320,7 @@ mod tests { // Should contain individual tags and pairs, but no triples assert!(result.iter().all(|combo| combo.len() <= 2)); - assert_eq!(result.len(), 6); // 3 individual + 3 pairs - } - - #[test] - fn test_create_tag_combinations_order() { - let tags = vec!["tag2".to_string(), "tag1".to_string(), "tag3".to_string()]; - let result = create_tag_combinations(&tags, 2); - - // Check that all combinations maintain alphabetical order - for combo in result { - if combo.len() > 1 { - assert!(combo.windows(2).all(|w| w[0] < w[1])); - } - } + assert_eq!(result.len(), 9); // 3 individual + 6 pairs } #[test] @@ -345,6 +330,6 @@ mod tests { // Convert to set to check for duplicates let result_set: std::collections::HashSet<_> = result.into_iter().collect(); - assert_eq!(result_set.len(), 7); // 3 individual + 3 pairs + 1 triple + assert_eq!(result_set.len(), 15); // 3 individual + 6 pairs + 9 triple } }