refactor: remove dead code, replace sum_matching tests with evaluate()
Removes unused methods (sum_matching, get_mut, item_by_name, item_index, top_level_groups, is_group_collapsed, show_item) and unused constants (LABEL_THRESHOLD, MIN_COL_WIDTH). The sum_matching tests in model.rs were bypassing the formula evaluator entirely. Replaced them with equivalent tests that call evaluate() against the existing Total = SUM(Revenue) formula, exercising the real aggregation code path. Also fixes a compile error in view.rs prop_tests where View/Axis imports and a doc comment were incorrectly commented out. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -93,31 +93,31 @@ impl Category {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn item_by_name(&self, name: &str) -> Option<&Item> {
|
||||
self.items.get(name)
|
||||
}
|
||||
// pub fn item_by_name(&self, name: &str) -> Option<&Item> {
|
||||
// self.items.get(name)
|
||||
// }
|
||||
|
||||
pub fn item_index(&self, name: &str) -> Option<usize> {
|
||||
self.items.get_index_of(name)
|
||||
}
|
||||
// pub fn item_index(&self, name: &str) -> Option<usize> {
|
||||
// self.items.get_index_of(name)
|
||||
// }
|
||||
|
||||
/// Returns item names in order, grouped hierarchically
|
||||
pub fn ordered_item_names(&self) -> Vec<&str> {
|
||||
self.items.keys().map(|s| s.as_str()).collect()
|
||||
}
|
||||
|
||||
/// Returns unique group names at the top level
|
||||
pub fn top_level_groups(&self) -> Vec<&str> {
|
||||
let mut seen = Vec::new();
|
||||
for item in self.items.values() {
|
||||
if let Some(g) = &item.group {
|
||||
if !seen.contains(&g.as_str()) {
|
||||
seen.push(g.as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
seen
|
||||
}
|
||||
// /// Returns unique group names at the top level
|
||||
// pub fn top_level_groups(&self) -> Vec<&str> {
|
||||
// let mut seen = Vec::new();
|
||||
// for item in self.items.values() {
|
||||
// if let Some(g) = &item.group {
|
||||
// if !seen.contains(&g.as_str()) {
|
||||
// seen.push(g.as_str());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// seen
|
||||
// }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -146,13 +146,13 @@ mod tests {
|
||||
assert_eq!(c.items.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_item_in_group_sets_group() {
|
||||
let mut c = cat();
|
||||
c.add_item_in_group("Jan", "Q1");
|
||||
let item = c.item_by_name("Jan").unwrap();
|
||||
assert_eq!(item.group.as_deref(), Some("Q1"));
|
||||
}
|
||||
// #[test]
|
||||
// fn add_item_in_group_sets_group() {
|
||||
// let mut c = cat();
|
||||
// c.add_item_in_group("Jan", "Q1");
|
||||
// let item = c.item_by_name("Jan").unwrap();
|
||||
// assert_eq!(item.group.as_deref(), Some("Q1"));
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn add_item_in_group_duplicate_returns_same_id() {
|
||||
@ -171,24 +171,24 @@ mod tests {
|
||||
assert_eq!(c.groups.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn top_level_groups_returns_unique_groups_in_insertion_order() {
|
||||
let mut c = cat();
|
||||
c.add_item_in_group("Jan", "Q1");
|
||||
c.add_item_in_group("Feb", "Q1");
|
||||
c.add_item_in_group("Apr", "Q2");
|
||||
let groups = c.top_level_groups();
|
||||
assert_eq!(groups, vec!["Q1", "Q2"]);
|
||||
}
|
||||
// #[test]
|
||||
// fn top_level_groups_returns_unique_groups_in_insertion_order() {
|
||||
// let mut c = cat();
|
||||
// c.add_item_in_group("Jan", "Q1");
|
||||
// c.add_item_in_group("Feb", "Q1");
|
||||
// c.add_item_in_group("Apr", "Q2");
|
||||
// let groups = c.top_level_groups();
|
||||
// assert_eq!(groups, vec!["Q1", "Q2"]);
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn item_index_reflects_insertion_order() {
|
||||
let mut c = cat();
|
||||
c.add_item("East");
|
||||
c.add_item("West");
|
||||
c.add_item("North");
|
||||
assert_eq!(c.item_index("East"), Some(0));
|
||||
assert_eq!(c.item_index("West"), Some(1));
|
||||
assert_eq!(c.item_index("North"), Some(2));
|
||||
}
|
||||
// #[test]
|
||||
// fn item_index_reflects_insertion_order() {
|
||||
// let mut c = cat();
|
||||
// c.add_item("East");
|
||||
// c.add_item("West");
|
||||
// c.add_item("North");
|
||||
// assert_eq!(c.item_index("East"), Some(0));
|
||||
// assert_eq!(c.item_index("West"), Some(1));
|
||||
// assert_eq!(c.item_index("North"), Some(2));
|
||||
// }
|
||||
}
|
||||
|
||||
@ -113,10 +113,6 @@ impl DataStore {
|
||||
self.cells.get(key)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, key: &CellKey) -> Option<&mut CellValue> {
|
||||
self.cells.get_mut(key)
|
||||
}
|
||||
|
||||
pub fn cells(&self) -> &HashMap<CellKey, CellValue> {
|
||||
&self.cells
|
||||
}
|
||||
@ -125,14 +121,6 @@ impl DataStore {
|
||||
self.cells.remove(key);
|
||||
}
|
||||
|
||||
/// Sum all cells matching partial coordinates
|
||||
pub fn sum_matching(&self, partial: &[(String, String)]) -> f64 {
|
||||
self.cells.iter()
|
||||
.filter(|(key, _)| key.matches_partial(partial))
|
||||
.filter_map(|(_, v)| v.as_f64())
|
||||
.sum()
|
||||
}
|
||||
|
||||
/// All cells where partial coords match
|
||||
pub fn matching_cells(&self, partial: &[(String, String)]) -> Vec<(&CellKey, &CellValue)> {
|
||||
self.cells.iter()
|
||||
@ -274,24 +262,6 @@ mod data_store {
|
||||
assert!(store.cells().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sum_matching_sums_across_dimension() {
|
||||
let mut store = DataStore::new();
|
||||
store.set(key(&[("Measure", "Revenue"), ("Region", "East")]), CellValue::Number(100.0));
|
||||
store.set(key(&[("Measure", "Revenue"), ("Region", "West")]), CellValue::Number(200.0));
|
||||
store.set(key(&[("Measure", "Cost"), ("Region", "East")]), CellValue::Number(50.0));
|
||||
let partial = vec![("Measure".to_string(), "Revenue".to_string())];
|
||||
assert_eq!(store.sum_matching(&partial), 300.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sum_matching_empty_partial_sums_everything() {
|
||||
let mut store = DataStore::new();
|
||||
store.set(key(&[("Region", "East")]), CellValue::Number(10.0));
|
||||
store.set(key(&[("Region", "West")]), CellValue::Number(20.0));
|
||||
assert_eq!(store.sum_matching(&[]), 30.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn matching_cells_returns_correct_subset() {
|
||||
let mut store = DataStore::new();
|
||||
@ -306,13 +276,6 @@ mod data_store {
|
||||
assert!(values.contains(&200.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_values_excluded_from_sum() {
|
||||
let mut store = DataStore::new();
|
||||
store.set(key(&[("Cat", "A")]), CellValue::Number(10.0));
|
||||
store.set(key(&[("Cat", "B")]), CellValue::Text("hello".into()));
|
||||
assert_eq!(store.sum_matching(&[]), 10.0);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -933,11 +933,11 @@ mod five_category {
|
||||
#[test]
|
||||
fn sum_revenue_for_east_region() {
|
||||
let m = build_model();
|
||||
let partial = vec![
|
||||
("Measure".to_string(), "Revenue".to_string()),
|
||||
let key = CellKey::new(vec![
|
||||
("Measure".to_string(), "Total".to_string()),
|
||||
("Region".to_string(), "East".to_string()),
|
||||
];
|
||||
let total = m.data.sum_matching(&partial);
|
||||
]);
|
||||
let total = m.evaluate(&key).and_then(|v| v.as_f64()).unwrap();
|
||||
let expected: f64 = DATA.iter().filter(|&&(r, _, _, _, _, _)| r == "East").map(|&(_, _, _, _, rev, _)| rev).sum();
|
||||
assert!(approx(total, expected), "expected {expected}, got {total}");
|
||||
}
|
||||
@ -945,11 +945,11 @@ mod five_category {
|
||||
#[test]
|
||||
fn sum_revenue_for_online_channel() {
|
||||
let m = build_model();
|
||||
let partial = vec![
|
||||
let key = CellKey::new(vec![
|
||||
("Channel".to_string(), "Online".to_string()),
|
||||
("Measure".to_string(), "Revenue".to_string()),
|
||||
];
|
||||
let total = m.data.sum_matching(&partial);
|
||||
("Measure".to_string(), "Total".to_string()),
|
||||
]);
|
||||
let total = m.evaluate(&key).and_then(|v| v.as_f64()).unwrap();
|
||||
let expected: f64 = DATA.iter().filter(|&&(_, _, ch, _, _, _)| ch == "Online").map(|&(_, _, _, _, rev, _)| rev).sum();
|
||||
assert!(approx(total, expected), "expected {expected}, got {total}");
|
||||
}
|
||||
@ -957,12 +957,12 @@ mod five_category {
|
||||
#[test]
|
||||
fn sum_revenue_for_shirts_q1() {
|
||||
let m = build_model();
|
||||
let partial = vec![
|
||||
("Measure".to_string(), "Revenue".to_string()),
|
||||
let key = CellKey::new(vec![
|
||||
("Measure".to_string(), "Total".to_string()),
|
||||
("Product".to_string(), "Shirts".to_string()),
|
||||
("Time".to_string(), "Q1".to_string()),
|
||||
];
|
||||
let total = m.data.sum_matching(&partial);
|
||||
]);
|
||||
let total = m.evaluate(&key).and_then(|v| v.as_f64()).unwrap();
|
||||
let expected: f64 = DATA.iter().filter(|&&(_, p, _, t, _, _)| p == "Shirts" && t == "Q1").map(|&(_, _, _, _, rev, _)| rev).sum();
|
||||
assert!(approx(total, expected), "expected {expected}, got {total}");
|
||||
}
|
||||
@ -970,8 +970,10 @@ mod five_category {
|
||||
#[test]
|
||||
fn sum_all_revenue_equals_grand_total() {
|
||||
let m = build_model();
|
||||
let partial = vec![("Measure".to_string(), "Revenue".to_string())];
|
||||
let total = m.data.sum_matching(&partial);
|
||||
let key = CellKey::new(vec![
|
||||
("Measure".to_string(), "Total".to_string()),
|
||||
]);
|
||||
let total = m.evaluate(&key).and_then(|v| v.as_f64()).unwrap();
|
||||
let expected: f64 = DATA.iter().map(|&(_, _, _, _, rev, _)| rev).sum();
|
||||
assert!(approx(total, expected), "expected {expected}, got {total}");
|
||||
}
|
||||
@ -1193,4 +1195,3 @@ mod prop_tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user