#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Task {
pub title: String,
pub score: u8,
pub actors: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Section {
pub name: Option<String>,
pub tasks: Vec<Task>,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct JourneyDiagram {
pub title: Option<String>,
pub sections: Vec<Section>,
}
impl JourneyDiagram {
pub fn total_tasks(&self) -> usize {
self.sections.iter().map(|s| s.tasks.len()).sum()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn total_tasks_across_sections() {
let diag = JourneyDiagram {
title: None,
sections: vec![
Section {
name: Some("A".to_string()),
tasks: vec![
Task {
title: "t1".to_string(),
score: 3,
actors: vec!["Me".to_string()],
},
Task {
title: "t2".to_string(),
score: 5,
actors: vec!["Me".to_string()],
},
],
},
Section {
name: Some("B".to_string()),
tasks: vec![Task {
title: "t3".to_string(),
score: 1,
actors: vec!["Cat".to_string()],
}],
},
],
};
assert_eq!(diag.total_tasks(), 3);
}
#[test]
fn total_tasks_empty_diagram() {
assert_eq!(JourneyDiagram::default().total_tasks(), 0);
}
}