From 21b77e2b322cc11aef60a7aee76d78a7ffa810e1 Mon Sep 17 00:00:00 2001 From: bluss Date: Mon, 16 Sep 2019 18:26:16 +0200 Subject: [PATCH] Apply formatting to tests --- src/arrayformat.rs | 69 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/src/arrayformat.rs b/src/arrayformat.rs index 2387d9b39..8812f1ae3 100644 --- a/src/arrayformat.rs +++ b/src/arrayformat.rs @@ -140,9 +140,14 @@ where &[len] => { let view = view.view().into_dimensionality::().unwrap(); f.write_str("[")?; - format_with_overflow(f, len, fmt_opt.collapse_limit(0), ", ", ELLIPSIS, |f, index| { - format(&view[index], f) - })?; + format_with_overflow( + f, + len, + fmt_opt.collapse_limit(0), + ", ", + ELLIPSIS, + |f, index| format(&view[index], f), + )?; f.write_str("]")?; } // For n-dimensional arrays, we proceed recursively @@ -289,16 +294,24 @@ mod formatting_with_omit { ); } - fn ellipsize(limit: usize, sep: &str, elements: impl IntoIterator) - -> String - { + fn ellipsize( + limit: usize, + sep: &str, + elements: impl IntoIterator, + ) -> String { let elements = elements.into_iter().collect::>(); let edge = limit / 2; if elements.len() <= limit { format!("{}", elements.iter().format(sep)) } else { - format!("{}{}{}{}{}", elements[..edge].iter().format(sep), sep, ELLIPSIS, sep, - elements[elements.len() - edge..].iter().format(sep)) + format!( + "{}{}{}{}{}", + elements[..edge].iter().format(sep), + sep, + ELLIPSIS, + sep, + elements[elements.len() - edge..].iter().format(sep) + ) } } @@ -348,7 +361,10 @@ mod formatting_with_omit { #[test] fn dim_2_last_axis_overflow() { let overflow: usize = 2; - let a = Array2::from_elem((AXIS_2D_OVERFLOW_LIMIT, AXIS_2D_OVERFLOW_LIMIT + overflow), 1); + let a = Array2::from_elem( + (AXIS_2D_OVERFLOW_LIMIT, AXIS_2D_OVERFLOW_LIMIT + overflow), + 1, + ); let actual = format!("{}", a); let expected = "\ [[1, 1, 1, 1, 1, ..., 1, 1, 1, 1, 1], @@ -370,7 +386,10 @@ mod formatting_with_omit { let a = Array2::from_elem((ARRAY_MANY_ELEMENT_LIMIT / 10, 10), 1); let actual = format!("{}", a); let row = format!("{}", a.row(0)); - let expected = format!("[{}]", ellipsize(AXIS_LIMIT_COL, ",\n ", (0..a.nrows()).map(|_| &row))); + let expected = format!( + "[{}]", + ellipsize(AXIS_LIMIT_COL, ",\n ", (0..a.nrows()).map(|_| &row)) + ); assert_str_eq(&expected, &actual); } @@ -386,17 +405,32 @@ mod formatting_with_omit { #[test] fn dim_2_multi_directional_overflow() { let overflow: usize = 2; - let a = Array2::from_elem((AXIS_2D_OVERFLOW_LIMIT + overflow, AXIS_2D_OVERFLOW_LIMIT + overflow), 1); + let a = Array2::from_elem( + ( + AXIS_2D_OVERFLOW_LIMIT + overflow, + AXIS_2D_OVERFLOW_LIMIT + overflow, + ), + 1, + ); let actual = format!("{}", a); let row = format!("[{}]", ellipsize(AXIS_LIMIT_ROW, ", ", a.row(0))); - let expected = format!("[{}]", ellipsize(AXIS_LIMIT_COL, ",\n ", (0..a.nrows()).map(|_| &row))); + let expected = format!( + "[{}]", + ellipsize(AXIS_LIMIT_COL, ",\n ", (0..a.nrows()).map(|_| &row)) + ); assert_str_eq(&expected, &actual); } #[test] fn dim_2_multi_directional_overflow_alternate() { let overflow: usize = 2; - let a = Array2::from_elem((AXIS_2D_OVERFLOW_LIMIT + overflow, AXIS_2D_OVERFLOW_LIMIT + overflow), 1); + let a = Array2::from_elem( + ( + AXIS_2D_OVERFLOW_LIMIT + overflow, + AXIS_2D_OVERFLOW_LIMIT + overflow, + ), + 1, + ); let actual = format!("{:#}", a); let row = format!("{}", a.row(0)); let expected = format!("[{}]", (0..a.nrows()).map(|_| &row).format(",\n ")); @@ -405,9 +439,12 @@ mod formatting_with_omit { #[test] fn dim_3_overflow_most() { - let a = Array3::from_shape_fn((AXIS_LIMIT_STACKED + 1, AXIS_LIMIT_COL, AXIS_LIMIT_ROW + 1), |(i, j, k)| { - 1000. + (100. * ((i as f64).sqrt() + (j as f64).sin() + k as f64)).round() / 100. - }); + let a = Array3::from_shape_fn( + (AXIS_LIMIT_STACKED + 1, AXIS_LIMIT_COL, AXIS_LIMIT_ROW + 1), + |(i, j, k)| { + 1000. + (100. * ((i as f64).sqrt() + (j as f64).sin() + k as f64)).round() / 100. + }, + ); let actual = format!("{:6.1}", a); let expected = "\ [[[1000.0, 1001.0, 1002.0, 1003.0, 1004.0, ..., 1007.0, 1008.0, 1009.0, 1010.0, 1011.0],