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 19, 2024
1 parent 7bbde3a commit 1fab0ea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
53 changes: 35 additions & 18 deletions pineappl/src/boc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub struct Order {
pub logxir: u32,
/// Exponent of the logarithm of the scale factor of the initial state factorization scale.
pub logxif: u32,
/// Exponent of the logarithm of the scale factor of the final state factorization scale (fragmentation scale).
/// Exponent of the logarithm of the scale factor of the final state factorization scale
/// (fragmentation scale).
pub logxia: u32,
}

Expand Down Expand Up @@ -261,6 +262,7 @@ impl Order {
&& match max_as.cmp(&max_al) {
Ordering::Greater => lo_as + pto == alphas,
Ordering::Less => lo_al + pto == alpha,
// TODO: when do we hit this condition?
Ordering::Equal => false,
})
},
Expand Down Expand Up @@ -415,16 +417,22 @@ impl Channel {
/// # Examples
///
/// ```rust
/// use pineappl::boc::Channel;
///
/// let entry1 = Channel::new(vec![(vec![2, 2], 2.0), (vec![4, 4], 2.0)]);
/// let entry2 = Channel::new(vec![(vec![4, 4], 1.0), (vec![2, 2], 1.0)]);
/// let entry3 = Channel::new(vec![(vec![3, 4], 1.0), (vec![2, 2], 1.0)]);
/// let entry4 = Channel::new(vec![(vec![4, 3], 1.0), (vec![2, 3], 2.0)]);
/// use pineappl::channel;
///
/// assert_eq!(entry1.common_factor(&entry2), Some(2.0));
/// assert_eq!(entry1.common_factor(&entry3), None);
/// assert_eq!(entry1.common_factor(&entry4), None);
/// let ch1 = channel![2, 2, 2.0; 4, 4, 2.0];
/// let ch2 = channel![4, 4, 1.0; 2, 2, 1.0];
/// let ch3 = channel![3, 4, 1.0; 2, 2, 1.0];
/// let ch4 = channel![4, 3, 1.0; 2, 3, 2.0];
/// let ch5 = channel![2, 2, 1.0; 4, 4, 2.0];
///
/// // ch1 is ch2 multiplied by two
/// assert_eq!(ch1.common_factor(&ch2), Some(2.0));
/// // ch1 isn't similar to ch3
/// assert_eq!(ch1.common_factor(&ch3), None);
/// // ch1 isn't similar to ch4 either
/// assert_eq!(ch1.common_factor(&ch4), None);
/// // ch1 is similar to ch5, but they don't share a common factor
/// assert_eq!(ch1.common_factor(&ch5), None);
/// ```
#[must_use]
pub fn common_factor(&self, other: &Self) -> Option<f64> {
Expand Down Expand Up @@ -519,14 +527,15 @@ impl FromStr for Channel {
/// ```
#[macro_export]
macro_rules! channel {
// TODO: generalize this to accept an arbitrary number of PIDs
($a:expr, $b:expr, $factor:expr $(; $c:expr, $d:expr, $fac:expr)*) => {
$crate::boc::Channel::new(vec![(vec![$a, $b], $factor), $((vec![$c, $d], $fac)),*])
};
}

#[cfg(test)]
mod tests {
use super::{Channel, Order, ParseOrderError};
use super::*;
use crate::pids;

#[test]
Expand All @@ -535,16 +544,17 @@ mod tests {
assert_eq!("a1".parse(), Ok(Order::new(0, 1, 0, 0, 0)));
assert_eq!("as1lr1".parse(), Ok(Order::new(1, 0, 1, 0, 0)));
assert_eq!("as1lf1".parse(), Ok(Order::new(1, 0, 0, 1, 0)));
assert_eq!("as1la1".parse(), Ok(Order::new(1, 0, 0, 0, 1)));
assert_eq!(
"ab12".parse::<Order>(),
Err(ParseOrderError("unknown coupling: 'ab'".to_owned()))
"ab12".parse::<Order>().unwrap_err().to_string(),
"unknown coupling: 'ab'"
);
assert_eq!(
"ab123456789000000".parse::<Order>(),
Err(ParseOrderError(
"error while parsing exponent of 'ab': number too large to fit in target type"
.to_owned()
))
"ab123456789000000"
.parse::<Order>()
.unwrap_err()
.to_string(),
"error while parsing exponent of 'ab': number too large to fit in target type"
);
}

Expand Down Expand Up @@ -784,5 +794,12 @@ mod tests {
.to_string(),
"missing ')' in ' ( 2, -2 '"
);

assert_eq!(
str::parse::<Channel>("1 * (2, 2, 2) + 2 * (4, 4)")
.unwrap_err()
.to_string(),
"PID tuples have different lengths"
);
}
}
2 changes: 1 addition & 1 deletion pineappl/src/fk_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ mod tests {
assert_eq!(FkAssumptions::from_str("Nf3Ind"), Ok(FkAssumptions::Nf3Ind));
assert_eq!(FkAssumptions::from_str("Nf3Sym"), Ok(FkAssumptions::Nf3Sym));
assert_eq!(
FkAssumptions::from_str("XXXXXX").unwrap().to_string(),
FkAssumptions::from_str("XXXXXX").unwrap_err().to_string(),
"unknown variant for FkAssumptions: XXXXXX"
);
}
Expand Down

0 comments on commit 1fab0ea

Please sign in to comment.