Skip to content

Commit

Permalink
Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cschwan committed Aug 20, 2024
1 parent 1fab0ea commit 2f06916
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 15 deletions.
9 changes: 7 additions & 2 deletions pineappl_cli/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ pub fn convolve_scales(
let mut alphas = |q2| match cfg.use_alphas_from {
0 => fun1.alphas_q2(q2),
1 => fun2.alphas_q2(q2),
// TODO: convert this into an error
_ => panic!(
"expected `use_alphas_from` to be `0` or `1`, is {}",
"expected `use_alphas_from` to be `0` or `1`, is `{}`",
cfg.use_alphas_from
),
};
Expand All @@ -321,7 +322,11 @@ pub fn convolve_scales(

grid.convolve(&mut cache, &orders, bins, channels, scales)
}
_ => unimplemented!(),
// TODO: convert this into an error
_ => panic!(
"convolutions with {} convolution functions is not supported",
conv_funs.len()
),
};

match mode {
Expand Down
39 changes: 38 additions & 1 deletion pineappl_cli/tests/convolve.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use assert_cmd::Command;
use predicates::str;

const HELP_STR: &str = "Convolutes a PineAPPL grid with a PDF set
Expand Down Expand Up @@ -30,6 +31,12 @@ const DEFAULT_STR: &str = "b etal dsig/detal
7 4 4.5 2.7517266e1
";

const USE_ALPHAS_FROM_ERROR_STR: &str = "expected `use_alphas_from` to be `0` or `1`, is `2`
";

const THREE_PDF_ERROR_STR: &str = "convolutions with 3 convolution functions is not supported
";

const FORCE_POSITIVE_STR: &str = "b etal dsig/detal
[] [pb]
-+----+----+-----------
Expand Down Expand Up @@ -179,15 +186,45 @@ fn default() {
Command::cargo_bin("pineappl")
.unwrap()
.args([
"--use-alphas-from=1",
"convolve",
"../test-data/LHCB_WP_7TEV.pineappl.lz4",
"NNPDF31_nlo_as_0118_luxqed",
"NNPDF31_nlo_as_0118_luxqed,NNPDF31_nlo_as_0118_luxqed",
])
.assert()
.success()
.stdout(DEFAULT_STR);
}

#[test]
fn use_alphas_from_error() {
Command::cargo_bin("pineappl")
.unwrap()
.args([
"--use-alphas-from=2",
"convolve",
"../test-data/LHCB_WP_7TEV.pineappl.lz4",
"NNPDF31_nlo_as_0118_luxqed,NNPDF31_nlo_as_0118_luxqed",
])
.assert()
.failure()
.stderr(str::contains(USE_ALPHAS_FROM_ERROR_STR));
}

#[test]
fn three_pdf_error() {
Command::cargo_bin("pineappl")
.unwrap()
.args([
"convolve",
"../test-data/LHCB_WP_7TEV.pineappl.lz4",
"NNPDF31_nlo_as_0118_luxqed,NNPDF31_nlo_as_0118_luxqed,NNPDF31_nlo_as_0118_luxqed",
])
.assert()
.failure()
.stderr(str::contains(THREE_PDF_ERROR_STR));
}

#[test]
fn force_positive() {
Command::cargo_bin("pineappl")
Expand Down
19 changes: 19 additions & 0 deletions pineappl_cli/tests/pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ const REPLICA0_STR: &str = "b etal total c pull c pull c pull c pull
7 4 4.5 1.215 0 1.426 1 -0.353 3 0.147 4 -0.003 2 -0.002
";

const LHAID_ERROR_STR: &str = "Error: no convolution function for LHAID = `0` found
";

#[test]
fn help() {
Command::cargo_bin("pineappl")
Expand Down Expand Up @@ -185,3 +188,19 @@ fn replica0() {
.success()
.stdout(REPLICA0_STR);
}

#[test]
fn conv_fun_lhaid_error() {
Command::cargo_bin("pineappl")
.unwrap()
.args([
"pull",
"--threads=1",
"../test-data/LHCB_WP_7TEV.pineappl.lz4",
"0",
"NNPDF40_nnlo_as_01180",
])
.assert()
.failure()
.stderr(LHAID_ERROR_STR);
}
24 changes: 12 additions & 12 deletions pineappl_cli/tests/uncert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ Options:
";

const DEFAULT_STR: &str =
"b etal dsig/detal NNPDF31_nlo_as_0118_luxqed NNPDF40_nnlo_as_01180
[] [pb] [pb] [%] [%] [pb] [%] [%]
-+----+----+-----------+-----------+---------+---------+-----------+--------+--------
0 2 2.25 7.7302788e2 7.7302788e2 -0.67 0.67 7.7302788e2 -0.62 0.62
1 2.25 2.5 7.0634852e2 7.0634851e2 -0.72 0.72 7.0634851e2 -0.62 0.62
2 2.5 2.75 6.1354750e2 6.1354750e2 -0.78 0.78 6.1354750e2 -0.64 0.64
3 2.75 3 4.9584391e2 4.9584391e2 -0.86 0.86 4.9584391e2 -0.68 0.68
4 3 3.25 3.6957893e2 3.6957893e2 -0.97 0.97 3.6957893e2 -0.76 0.76
5 3.25 3.5 2.5143057e2 2.5143057e2 -1.14 1.14 2.5143057e2 -0.89 0.89
6 3.5 4 1.1962468e2 1.1962468e2 -1.55 1.55 1.1962468e2 -1.34 1.34
7 4 4.5 2.9665790e1 2.9665790e1 -2.56 2.56 2.9665789e1 -3.51 3.51
"b etal dsig/detal 324900 NNPDF40_nnlo_as_01180
[] [pb] [pb] [%] [%] [pb] [%] [%]
-+----+----+-----------+-----------+--------+--------+-----------+--------+--------
0 2 2.25 7.7302788e2 7.7302788e2 -0.67 0.67 7.7302788e2 -0.62 0.62
1 2.25 2.5 7.0634852e2 7.0634851e2 -0.72 0.72 7.0634851e2 -0.62 0.62
2 2.5 2.75 6.1354750e2 6.1354750e2 -0.78 0.78 6.1354750e2 -0.64 0.64
3 2.75 3 4.9584391e2 4.9584391e2 -0.86 0.86 4.9584391e2 -0.68 0.68
4 3 3.25 3.6957893e2 3.6957893e2 -0.97 0.97 3.6957893e2 -0.76 0.76
5 3.25 3.5 2.5143057e2 2.5143057e2 -1.14 1.14 2.5143057e2 -0.89 0.89
6 3.5 4 1.1962468e2 1.1962468e2 -1.55 1.55 1.1962468e2 -1.34 1.34
7 4 4.5 2.9665790e1 2.9665790e1 -2.56 2.56 2.9665789e1 -3.51 3.51
";

const CL_90_STR: &str = "b etal dsig/detal NNPDF31_nlo_as_0118_luxqed
Expand Down Expand Up @@ -170,7 +170,7 @@ fn conv_fun_default() {
"--conv-fun=0,1",
"--threads=1",
"../test-data/LHCB_WP_7TEV.pineappl.lz4",
"NNPDF31_nlo_as_0118_luxqed,NNPDF40_nnlo_as_01180=NNPDF3.1+NNPDF4.0",
"324900,NNPDF40_nnlo_as_01180=NNPDF3.1+NNPDF4.0",
])
.assert()
.success()
Expand Down

0 comments on commit 2f06916

Please sign in to comment.