diff --git a/pineappl/src/empty_subgrid.rs b/pineappl/src/empty_subgrid.rs index 5f2acfea..4977d082 100644 --- a/pineappl/src/empty_subgrid.rs +++ b/pineappl/src/empty_subgrid.rs @@ -55,6 +55,8 @@ impl Subgrid for EmptySubgridV1 { #[cfg(test)] mod tests { use super::*; + use crate::packed_array::PackedArray; + use crate::packed_subgrid::PackedQ1X2SubgridV1; use crate::v0; #[test] @@ -84,6 +86,21 @@ mod tests { subgrid.fill(&v0::default_interps(2), &[0.0; 3], 0.0); } + #[test] + #[should_panic( + expected = "EmptySubgridV1 doesn't support the merge operation for non-empty subgrids" + )] + fn merge_non_empty() { + let mut subgrid_lhs = EmptySubgridV1; + + let mut array = PackedArray::new(vec![1, 1]); + array[0] = 1.0; + let node_values = vec![NodeValues::UseThese(vec![1.0]); 2]; + let subgrid_rhs = PackedQ1X2SubgridV1::new(array, node_values).into(); + + subgrid_lhs.merge(&subgrid_rhs, None); + } + #[test] fn node_values() { assert!(EmptySubgridV1.node_values().is_empty()); diff --git a/pineappl/src/fk_table.rs b/pineappl/src/fk_table.rs index f5ec3e76..5c3e117b 100644 --- a/pineappl/src/fk_table.rs +++ b/pineappl/src/fk_table.rs @@ -211,12 +211,12 @@ impl FkTable { /// Returns the single `muf2` scale of this `FkTable`. #[must_use] pub fn muf2(&self) -> f64 { - if let &[muf2] = &self.grid.evolve_info(&[true]).fac1[..] { - muf2 - } else { - // every `FkTable` has only a single factorization scale - unreachable!() - } + let [muf2] = self.grid.evolve_info(&[true]).fac1[..] + .try_into() + // UNWRAP: every `FkTable` has only a single factorization scale + .unwrap_or_else(|_| unreachable!()); + + muf2 } /// Returns the x grid that all subgrids for all hadronic initial states share. diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index 02dac604..19ddcb06 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -166,7 +166,9 @@ impl Grid { assert_eq!( interps.len(), kinematics.len(), - "interps and kinematics have different lengths" + "interps and kinematics have different lengths: {} vs. {}", + interps.len(), + kinematics.len(), ); assert!( @@ -1618,7 +1620,7 @@ mod tests { #[test] #[should_panic(expected = "channel #0 has wrong number of PIDs: expected 2, found 3")] - fn grid_new_panic() { + fn grid_new_panic0() { let channel = vec![(vec![1, -1, 1], 1.0), (vec![2, -2, 2], 1.0)]; let _ = Grid::new( @@ -1640,6 +1642,64 @@ mod tests { ); } + #[test] + #[should_panic(expected = "interps and kinematics have different lengths: 2 vs. 3")] + fn grid_new_panic1() { + let channel = vec![(vec![1, -1], 1.0), (vec![2, -2], 1.0)]; + + let _ = Grid::new( + PidBasis::Pdg, + vec![Channel::new(channel)], + vec![Order::new(0, 2, 0, 0, 0)], + vec![0.0, 1.0], + vec![ + Conv::new(ConvType::UnpolPDF, 2212), + Conv::new(ConvType::UnpolPDF, 2212), + ], + v0::default_interps(1), + vec![Kinematics::Scale(0), Kinematics::X1, Kinematics::X2], + Scales { + ren: ScaleFuncForm::Scale(0), + fac: ScaleFuncForm::Scale(0), + frg: ScaleFuncForm::NoScale, + }, + ); + } + + #[test] + #[should_panic(expected = "scales and kinematics are not compatible")] + fn grid_new_panic2() { + let channel = vec![(vec![1, -1], 1.0), (vec![2, -2], 1.0)]; + + let _ = Grid::new( + PidBasis::Pdg, + vec![Channel::new(channel)], + vec![Order::new(0, 2, 0, 0, 0)], + vec![0.0, 1.0], + vec![ + Conv::new(ConvType::UnpolPDF, 2212), + Conv::new(ConvType::UnpolPDF, 2212), + ], + v0::default_interps(2), + vec![Kinematics::Scale(0), Kinematics::X1, Kinematics::X2], + Scales { + ren: ScaleFuncForm::Scale(0), + fac: ScaleFuncForm::Scale(1), + frg: ScaleFuncForm::NoScale, + }, + ); + } + + #[test] + fn grid_read_file_version_unsupported() { + assert!(matches!( + Grid::read( + &[b'P', b'i', b'n', b'e', b'A', b'P', b'P', b'L', 99, 0, 0, 0, 0, 0, 0, 0][..] + ), + Err(GridError::FileVersionUnsupported { file_version: 99 }) + )); + } + #[test] fn grid_merge_empty_subgrids() { let mut grid = Grid::new( @@ -1898,6 +1958,35 @@ mod tests { ); } + #[test] + fn grid_set_remapper_bin_number_mismatch() { + let mut grid = Grid::new( + PidBasis::Pdg, + vec![ + channel![2, 2, 1.0; 4, 4, 1.0], + channel![1, 1, 1.0; 3, 3, 1.0], + ], + vec![Order::new(0, 2, 0, 0, 0)], + vec![0.0, 0.25, 0.5, 0.75, 1.0], + vec![Conv::new(ConvType::UnpolPDF, 2212); 2], + v0::default_interps(2), + vec![Kinematics::Scale(0), Kinematics::X1, Kinematics::X2], + Scales { + ren: ScaleFuncForm::Scale(0), + fac: ScaleFuncForm::Scale(0), + frg: ScaleFuncForm::NoScale, + }, + ); + + assert!(matches!( + grid.set_remapper(BinRemapper::new(vec![1.0], vec![(0.0, 1.0)]).unwrap()), + Err(GridError::BinNumberMismatch { + grid_bins: 4, + remapper_bins: 1 + }) + )); + } + #[test] fn evolve_info() { let grid = diff --git a/pineappl_cli/tests/evolve.rs b/pineappl_cli/tests/evolve.rs index 7e862ada..4f50125c 100644 --- a/pineappl_cli/tests/evolve.rs +++ b/pineappl_cli/tests/evolve.rs @@ -171,7 +171,7 @@ const NUTEV_CC_NU_FE_SIGMARED_STR: &str = "b Grid FkTable rel. dif const CMS_TTB_8TEV_2D_TTM_TRAP_TOT_STR: &str = "b Grid FkTable rel. diff -+-----------+-----------+------------- -0 2.1596192e2 2.1590144e2 -2.8005486e-4 +0 2.0680644e2 2.0666857e2 -6.6663644e-4 "; const STAR_WMWP_510GEV_WM_AL_POL: &str = "b Grid FkTable rel. diff @@ -406,6 +406,7 @@ fn cms_ttb_8tev_2d_ttm_trap_tot() { .args([ "evolve", "--orders=as2,as3,as4", + "--xir=2", "../test-data/CMS_TTB_8TEV_2D_TTM_TRAP_TOT-opt.pineappl.lz4", "../test-data/CMS_TTB_8TEV_2D_TTM_TRAP_TOT.tar", output.path().to_str().unwrap(),