Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn print_t_test(t_test: &TTest, s1: &Summary, s2: &Summary) {
println!("{l:>w$} = {v}", w = width, l = "DF", v = t_test.df);
}

fn summarize_file(path: &str, lax_parsing: bool) -> Result<Summary, Box<error::Error>> {
fn summarize_file(path: &str, lax_parsing: bool) -> Result<Summary, Box<dyn error::Error>> {
let f = File::open(path).or_else(|e| {
log::error(&format!("Could not open file: {:?}", path));
Err(e)
Expand All @@ -120,7 +120,7 @@ fn summarize_file(path: &str, lax_parsing: bool) -> Result<Summary, Box<error::E
Ok(Summary::new(&data)?)
}

fn read_data<R>(reader: R, lax_parsing: bool) -> Result<Vec<f64>, Box<error::Error>>
fn read_data<R>(reader: R, lax_parsing: bool) -> Result<Vec<f64>, Box<dyn error::Error>>
where R: BufRead {
let mut data: Vec<f64> = vec![];

Expand All @@ -140,7 +140,7 @@ fn read_data<R>(reader: R, lax_parsing: bool) -> Result<Vec<f64>, Box<error::Err
Ok(data)
}

fn summarize_stdin(lax_parsing: bool) -> Result<Summary, Box<error::Error>> {
fn summarize_stdin(lax_parsing: bool) -> Result<Summary, Box<dyn error::Error>> {
let stdin = io::stdin();
let data = read_data(stdin.lock(), lax_parsing)?;

Expand Down
22 changes: 11 additions & 11 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ pub enum Error {

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
write!(f, "{}", std::error::Error::description(self))
write!(
f,
"{}",
match *self {
Error::BadSample => "All sample data must be finite",
Error::Diverged => "Numeric evaluation diverged",
Error::EmptySample => "Sample data set cannot be empty",
Error::Undefined => "Function undefined for argument",
}
)
}
}

impl std::error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::BadSample => "All sample data must be finite",
Error::Diverged => "Numeric evaluation diverged",
Error::EmptySample => "Sample data set cannot be empty",
Error::Undefined => "Function undefined for argument",
}
}
}
impl std::error::Error for Error {}
6 changes: 2 additions & 4 deletions tests/support/kat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ macro_rules! assert_appx_eq {
($name:expr, $tolerance:expr, $known:expr, $actual:expr) => {
let d = ($known - $actual).abs();

let err = format!("{}: {} and {} differ by {} > {}",
$name, $known, $actual, d, $tolerance);

assert!(d < $tolerance, err);
assert!(d < $tolerance, "{}: {} and {} differ by {} > {}",
$name, $known, $actual, d, $tolerance);
};
}

Expand Down