Skip to content

Commit 1601cc5

Browse files
committed
Set exit average to NAN when no functions
1 parent 676e798 commit 1601cc5

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

‎src/metrics/exit.rs‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ impl Stats {
5757
///
5858
/// This value is computed dividing the `NExit` value
5959
/// for the total number of functions/closures in a space.
60+
///
61+
/// If there are no functions in a code, its value is `NAN`.
6062
pub fn exit_average(&self) -> f64 {
6163
self.exit() / self.total_space_functions as f64
6264
}
@@ -143,6 +145,54 @@ mod tests {
143145

144146
use super::*;
145147

148+
#[test]
149+
fn python_no_exit() {
150+
check_metrics!(
151+
"a = 42",
152+
"foo.py",
153+
PythonParser,
154+
nexits,
155+
[(exit, 0, usize)],
156+
[(exit_average, f64::NAN)] // 0 functions
157+
);
158+
}
159+
160+
#[test]
161+
fn rust_no_exit() {
162+
check_metrics!(
163+
"let a = 42;",
164+
"foo.rs",
165+
RustParser,
166+
nexits,
167+
[(exit, 0, usize)],
168+
[(exit_average, f64::NAN)] // 0 functions
169+
);
170+
}
171+
172+
#[test]
173+
fn c_no_exit() {
174+
check_metrics!(
175+
"int a = 42;",
176+
"foo.c",
177+
CppParser,
178+
nexits,
179+
[(exit, 0, usize)],
180+
[(exit_average, f64::NAN)] // 0 functions
181+
);
182+
}
183+
184+
#[test]
185+
fn javascript_no_exit() {
186+
check_metrics!(
187+
"var a = 42;",
188+
"foo.js",
189+
JavascriptParser,
190+
nexits,
191+
[(exit, 0, usize)],
192+
[(exit_average, f64::NAN)] // 0 functions
193+
);
194+
}
195+
146196
#[test]
147197
fn python_simple_function() {
148198
check_metrics!(

0 commit comments

Comments
 (0)