1use std::fmt;
4
5pub const ALPHA: f64 = 0.01;
7
8#[derive(Debug, Clone)]
10pub struct TestResult {
11 pub name: &'static str,
13 pub p_value: f64,
16 pub note: Option<String>,
18}
19
20impl TestResult {
21 pub fn new(name: &'static str, p_value: f64) -> Self {
23 Self {
24 name,
25 p_value,
26 note: None,
27 }
28 }
29
30 pub fn with_note(name: &'static str, p_value: f64, note: impl Into<String>) -> Self {
32 Self {
33 name,
34 p_value,
35 note: Some(note.into()),
36 }
37 }
38
39 pub fn insufficient(name: &'static str, reason: &str) -> Self {
41 Self {
42 name,
43 p_value: f64::NAN,
44 note: Some(reason.to_owned()),
45 }
46 }
47
48 pub fn passed(&self) -> bool {
50 self.p_value >= ALPHA
51 }
52
53 pub fn skipped(&self) -> bool {
55 self.p_value.is_nan()
56 }
57}
58
59impl fmt::Display for TestResult {
60 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61 let status = if self.skipped() {
62 "SKIP"
63 } else if self.passed() {
64 "PASS"
65 } else {
66 "FAIL"
67 };
68 if self.skipped() {
69 write!(f, "[{status}] {:<48} p = N/A", self.name)?;
70 } else {
71 write!(f, "[{status}] {:<48} p = {:.6}", self.name, self.p_value)?;
72 }
73 if let Some(n) = &self.note {
74 write!(f, " ({n})")?;
75 }
76 Ok(())
77 }
78}