Skip to content

Commit

Permalink
Increase code coverage a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Oct 12, 2024
1 parent 823b20f commit d4d9ec1
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 9 deletions.
17 changes: 17 additions & 0 deletions pineappl/src/empty_subgrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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());
Expand Down
12 changes: 6 additions & 6 deletions pineappl/src/fk_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
93 changes: 91 additions & 2 deletions pineappl/src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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 =
Expand Down
3 changes: 2 additions & 1 deletion pineappl_cli/tests/evolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit d4d9ec1

Please sign in to comment.