fix tests
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 10 Apr 2025 02:55:52 +0000 (19:55 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 10 Apr 2025 02:55:52 +0000 (19:55 -0700)
rust/pspp/src/output/pivot/test.rs

index 022487d9f338af06553943a9f5eec584cbb64247..35d1481701fdc7263be4d1ed14a64d8ceaf099dd 100644 (file)
@@ -2,7 +2,7 @@ use std::{fs::File, sync::Arc};
 
 use crate::output::{
     driver::Driver,
-    pivot::{Area, Color, Look, PivotTable},
+    pivot::{Area, Axis2, Color, Look, PivotTable},
     text::TextDriver,
     Details, Item,
 };
@@ -45,24 +45,27 @@ fn pivot_table_1d() {
     driver.write(&Arc::new(Item::new(Details::Table(Box::new(pt)))));
 }
 
-fn d2() -> PivotTable {
+fn test_look() -> Arc<Look> {
     let mut look = Look::default();
     look.areas[Area::Title].cell_style.horz_align = Some(super::HorzAlign::Left);
     look.areas[Area::Title].font_style.bold = false;
+    Arc::new(look)
+}
 
+fn d2(title: &str, axes: [Axis3; 2]) -> PivotTable {
     let mut a = GroupBuilder::new(Value::new_text("a"));
     for name in ["a1", "a2", "a3"] {
         a.push(Value::new_text(name));
     }
-    let d1 = DimensionBuilder::new(Axis3::X, a);
+    let d1 = DimensionBuilder::new(axes[0], a);
 
     let mut b = GroupBuilder::new(Value::new_text("b"));
     for name in ["b1", "b2", "b3"] {
         b.push(Value::new_text(name));
     }
-    let d2 = DimensionBuilder::new(Axis3::X, b);
+    let d2 = DimensionBuilder::new(axes[1], b);
 
-    let mut pt = PivotTableBuilder::new(Value::new_text("Columns"), &[d1, d2]);
+    let mut pt = PivotTableBuilder::new(Value::new_text(title), &[d1, d2]);
     let mut i = 0;
     for b in 0..3 {
         for a in 0..3 {
@@ -70,13 +73,13 @@ fn d2() -> PivotTable {
             i += 1;
         }
     }
-    pt.with_look(Arc::new(look)).build()
+    pt.with_look(test_look()).build()
 }
 
 #[test]
-fn d2_columns() {
+fn d2_cc() {
     assert_eq!(
-        d2().to_string(),
+        d2("Columns", [Axis3::X, Axis3::X]).to_string(),
         "\
 Columns
 ╭────────┬────────┬────────╮
@@ -91,12 +94,9 @@ Columns
 }
 
 #[test]
-fn d2_rows() {
-    let mut pt = d2();
-    pt.transpose();
-    pt.title = Some(Box::new(Value::new_text("Rows")));
+fn d2_rr() {
     assert_eq!(
-        pt.to_string(),
+        d2("Rows", [Axis3::Y, Axis3::Y]).to_string(),
         "\
 Rows
 ╭─────┬─╮
@@ -117,13 +117,9 @@ Rows
 }
 
 #[test]
-fn d2_column_row() {
-    let mut pt = d2();
-    pt.transpose();
-    pt.move_dimension(0, Axis3::X, 0);
-    pt.title = Some(Box::new(Value::new_text("Column x Row")));
+fn d2_cr() {
     assert_eq!(
-        pt.to_string(),
+        d2("Column x Row", [Axis3::X, Axis3::Y]).to_string(),
         "\
 Column x Row
 ╭──┬──┬──┬──╮
@@ -138,14 +134,9 @@ Column x Row
 }
 
 #[test]
-fn d2_row_column() {
-    let mut pt = d2();
-    pt.transpose();
-    pt.move_dimension(0, Axis3::X, 0);
-    pt.transpose();
-    pt.title = Some(Box::new(Value::new_text("Row x Column")));
+fn d2_rc() {
     assert_eq!(
-        pt.to_string(),
+        d2("Row x Column", [Axis3::Y, Axis3::X]).to_string(),
         "\
 Row x Column
 ╭──┬──┬──┬──╮