Skip to content

Commit

Permalink
Set exit average to NAN when no functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Luni-4 committed Jan 11, 2021
1 parent 676e798 commit 1601cc5
Showing 1 changed file with 50 additions and 0 deletions.
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

0 comments on commit 1601cc5

Please sign in to comment.