Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,12 @@ macro_rules! check_metrics {

$(
$(
assert!((func_space.metrics.$metric.$func_float() - $true_float_value).abs() < f64::EPSILON);
let value: f64 = $true_float_value;
if !value.is_nan() {
assert!((func_space.metrics.$metric.$func_float() - value).abs() < f64::EPSILON);
} else {
assert!(func_space.metrics.$metric.$func_float().is_nan());
}
)*
)?
}
Expand Down
50 changes: 50 additions & 0 deletions src/metrics/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ impl Stats {
///
/// This value is computed dividing the `NExit` value
/// for the total number of functions/closures in a space.
///
/// If there are no functions in a code, its value is `NAN`.
pub fn exit_average(&self) -> f64 {
self.exit() / self.total_space_functions as f64
}
Expand Down Expand Up @@ -143,6 +145,54 @@ mod tests {

use super::*;

#[test]
fn python_no_exit() {
check_metrics!(
"a = 42",
"foo.py",
PythonParser,
nexits,
[(exit, 0, usize)],
[(exit_average, f64::NAN)] // 0 functions
);
}

#[test]
fn rust_no_exit() {
check_metrics!(
"let a = 42;",
"foo.rs",
RustParser,
nexits,
[(exit, 0, usize)],
[(exit_average, f64::NAN)] // 0 functions
);
}

#[test]
fn c_no_exit() {
check_metrics!(
"int a = 42;",
"foo.c",
CppParser,
nexits,
[(exit, 0, usize)],
[(exit_average, f64::NAN)] // 0 functions
);
}

#[test]
fn javascript_no_exit() {
check_metrics!(
"var a = 42;",
"foo.js",
JavascriptParser,
nexits,
[(exit, 0, usize)],
[(exit_average, f64::NAN)] // 0 functions
);
}

#[test]
fn python_simple_function() {
check_metrics!(
Expand Down