crap4rust/
crap_formula.rs1use crate::verdict::Verdict;
6
7#[derive(Debug, Clone, Copy, Default)]
8pub struct CrapFormula;
9
10impl CrapFormula {
11 #[must_use]
12 pub const fn new() -> Self {
13 Self
14 }
15
16 #[must_use]
17 pub fn score(&self, complexity: u32, coverage: f64) -> f64 {
18 let complexity = f64::from(complexity);
19 complexity.powi(2) * (1.0 - coverage).powi(3) + complexity
20 }
21
22 #[must_use]
23 pub fn classify(&self, score: f64, threshold: f64, warn_threshold: f64) -> Verdict {
24 if score > threshold {
25 Verdict::Crappy
26 } else if score >= warn_threshold {
27 Verdict::Warn
28 } else {
29 Verdict::Clean
30 }
31 }
32}