From: Ben Pfaff Date: Tue, 6 Jan 2026 00:06:46 +0000 (-0800) Subject: Add another lightweight test. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6744c6ba52e7fb4afa1e3f55918f90b36c233929;p=pspp Add another lightweight test. --- diff --git a/rust/pspp/src/spv/read/light.rs b/rust/pspp/src/spv/read/light.rs index e603b58988..2a2f4d8692 100644 --- a/rust/pspp/src/spv/read/light.rs +++ b/rust/pspp/src/spv/read/light.rs @@ -14,7 +14,6 @@ use chrono::DateTime; use displaydoc::Display; use encoding_rs::{Encoding, WINDOWS_1252}; use enum_map::{EnumMap, enum_map}; -use itertools::Itertools; use crate::{ data::Datum, @@ -255,7 +254,7 @@ impl LightTable { } }), title: Some(Box::new( - self.titles.title.decode(encoding, &footnotes, warn), + self.titles.user_title.decode(encoding, &footnotes, warn), )), subtype: Some(Box::new( self.titles.subtype.decode(encoding, &footnotes, warn), @@ -1762,7 +1761,6 @@ impl Axes { ) -> Result, (LightWarning, Vec)> { let n = self.layers.len() + self.rows.len() + self.columns.len(); if n != dimensions.len() { - // Warn, then treat all of the dimensions as rows. return Err(( LightWarning::WrongAxisCount { expected: dimensions.len(), @@ -1779,19 +1777,34 @@ impl Axes { dimensions.iter().map(move |d| (axis, *d as usize)) } - let mut axes = vec![None; n]; + let mut dimensions = dimensions.into_iter().map(Some).collect::>(); + let mut output = Vec::with_capacity(n); + for (axis, index) in axis_dims(Axis3::Z, &self.layers) .chain(axis_dims(Axis3::Y, &self.rows)) .chain(axis_dims(Axis3::X, &self.columns)) { - if index >= n { - return Err((LightWarning::InvalidDimensionIndex { index, n }, dimensions)); - } else if axes[index].is_some() { - return Err((LightWarning::DuplicateDimensionIndex(index), dimensions)); + let result = dimensions + .get_mut(index) + .ok_or(LightWarning::InvalidDimensionIndex { index, n }) + .and_then(|dimension| { + dimension + .take() + .ok_or(LightWarning::DuplicateDimensionIndex(index)) + }); + match result { + Ok(dimension) => output.push((axis, dimension)), + Err(error) => { + let dimensions = dimensions + .into_iter() + .flatten() + .chain(output.into_iter().map(|(_axis, dimension)| dimension)) + .collect(); + return Err((error, dimensions)); + } } - axes[index] = Some(axis); } - Ok(axes.into_iter().flatten().zip_eq(dimensions).collect()) + Ok(output) } } diff --git a/rust/pspp/src/spv/read/tests.rs b/rust/pspp/src/spv/read/tests.rs index 57e24a961c..bda6783e94 100644 --- a/rust/pspp/src/spv/read/tests.rs +++ b/rust/pspp/src/spv/read/tests.rs @@ -13,11 +13,19 @@ use crate::{ spv::SpvArchive, }; +/// Checks that reordering categories works properly. #[test] fn light1() { test_raw_spvfile("light1", None); } +/// Checks that dimensions are ordered properly and that the title reflects the +/// user's changes. +#[test] +fn light2() { + test_raw_spvfile("light2", None); +} + #[test] fn legacy1() { test_raw_spvfile("legacy1", None); diff --git a/rust/pspp/src/spv/testdata/light2.expected b/rust/pspp/src/spv/testdata/light2.expected new file mode 100644 index 0000000000..5650a27ede --- /dev/null +++ b/rust/pspp/src/spv/testdata/light2.expected @@ -0,0 +1,24 @@ + Crosstabulation +╭──────────────────────────────┬───────────────────────┬──────╮ +│ │ Variable B │ │ +│ ├──────┬────────┬───────┤ │ +│ │Normal│Marginal│Extreme│ Total│ +├──────────────────────────────┼──────┼────────┼───────┼──────┤ +│Variable A Less Count │ 10│ 7.0│ 45.5%│ 52.6%│ +│ Expected Count│ 18.2%│ 20.0%│ 6.7%│ 22│ +│ % within A │ 15.0%│ 13│ 13.3│ 34.2%│ +│ % within B │ 38.0│ 100.0%│ 63.3%│ 63.3%│ +│ % of Total │100.0%│ 35.0%│ 20│ 20.0│ +│ ╶───────────────────┼──────┼────────┼───────┼──────┤ +│ More Count │ 16.7%│ 8│ 7.7│ 36.4%│ +│ Expected Count│ 22.0│ 100.0%│ 36.7%│ 36.7%│ +│ % within A │ 61.9%│ 21.7%│ 16│ 12.7│ +│ % within B │ 19│ 19.0│ 31.7%│100.0%│ +│ % of Total │ 33.3%│ 100.0%│ 33.3%│ 60│ +├──────────────────────────────┼──────┼────────┼───────┼──────┤ +│Total Count │ 38.1%│ 13.3%│ 4│ 7.3│ +│ Expected Count│ 9│ 12.0│ 23.7%│ 47.4%│ +│ % within A │ 42.1%│ 80.0%│ 26.7%│ 38│ +│ % within B │ 31.7%│ 21│ 21.0│ 35.0%│ +│ % of Total │ 60.0│ 100.0%│ 100.0%│100.0%│ +╰──────────────────────────────┴──────┴────────┴───────┴──────╯ diff --git a/rust/pspp/src/spv/testdata/light2.spv b/rust/pspp/src/spv/testdata/light2.spv new file mode 100644 index 0000000000..9e9210cb4b Binary files /dev/null and b/rust/pspp/src/spv/testdata/light2.spv differ