test(import): add tests for label field import behavior
Add two new tests for label field functionality: - label_fields_imported_as_label_category_coords: Verifies that high-cardinality fields (>20 distinct values) are classified as Label kind, default to accepted, and are stored as category coords - label_category_defaults_to_none_axis: Verifies that label categories default to Axis::None in the active view Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/Qwen3.5-35B-A3B-GGUF:Q5_K_M)
This commit is contained in:
@ -631,6 +631,46 @@ mod tests {
|
|||||||
assert!(model.category("Measure").is_some());
|
assert!(model.category("Measure").is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn label_fields_imported_as_label_category_coords() {
|
||||||
|
use crate::model::category::CategoryKind;
|
||||||
|
// 25 unique descriptions → classified as Label (> CATEGORY_THRESHOLD=20)
|
||||||
|
let records: Vec<serde_json::Value> = (0..25)
|
||||||
|
.map(|i| json!({"region": "East", "desc": format!("row-{i}"), "revenue": i as f64}))
|
||||||
|
.collect();
|
||||||
|
let raw = serde_json::Value::Array(records);
|
||||||
|
let p = ImportPipeline::new(raw);
|
||||||
|
let desc = p.proposals.iter().find(|p| p.field == "desc").unwrap();
|
||||||
|
assert_eq!(desc.kind, FieldKind::Label);
|
||||||
|
assert!(desc.accepted, "labels should default to accepted");
|
||||||
|
|
||||||
|
let model = p.build_model().unwrap();
|
||||||
|
// Label field exists as a category with Label kind
|
||||||
|
let cat = model.category("desc").expect("desc category exists");
|
||||||
|
assert_eq!(cat.kind, CategoryKind::Label);
|
||||||
|
// Each record's cell key carries the desc label coord
|
||||||
|
use crate::model::cell::CellKey;
|
||||||
|
let k = CellKey::new(vec![
|
||||||
|
("Measure".to_string(), "revenue".to_string()),
|
||||||
|
("desc".to_string(), "row-7".to_string()),
|
||||||
|
("region".to_string(), "East".to_string()),
|
||||||
|
]);
|
||||||
|
assert_eq!(model.get_cell(&k).and_then(|v| v.as_f64()), Some(7.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn label_category_defaults_to_none_axis() {
|
||||||
|
use crate::view::Axis;
|
||||||
|
let records: Vec<serde_json::Value> = (0..25)
|
||||||
|
.map(|i| json!({"region": "East", "desc": format!("r{i}"), "n": 1.0}))
|
||||||
|
.collect();
|
||||||
|
let raw = serde_json::Value::Array(records);
|
||||||
|
let p = ImportPipeline::new(raw);
|
||||||
|
let model = p.build_model().unwrap();
|
||||||
|
let v = model.active_view();
|
||||||
|
assert_eq!(v.axis_of("desc"), Axis::None);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_model_cells_match_source_data() {
|
fn build_model_cells_match_source_data() {
|
||||||
let raw = json!([
|
let raw = json!([
|
||||||
|
|||||||
Reference in New Issue
Block a user