From 42b139f1a5de3f030c6d6640137d4fb25f77a38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Tue, 6 Apr 2021 03:08:44 -0300 Subject: [PATCH] Add tests for byte pretty-printing --- src/test.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/src/test.rs b/src/test.rs index ebc32f8..3fc5065 100644 --- a/src/test.rs +++ b/src/test.rs @@ -26,7 +26,7 @@ where } #[cfg(test)] -mod tests { +mod argparsing { use super::{make_dummy_files}; use crate::cli; use crate::cli::Command; @@ -103,6 +103,77 @@ mod tests { } } +#[cfg(test)] +mod byte_pretty_printing { + use crate::bytes::Bytes; + #[test] + fn bytes () { + assert_eq!( + &format!("{}", Bytes::new(234)), + "234.00 B" + ); + + assert_eq!( + &format!("{}", Bytes::new(999)), + "999.00 B" + ); + } + + #[test] + fn kilobytes () { + assert_eq!( + &format!("{}", Bytes::new(2234)), + "2.23 kB" + ); + + assert_eq!( + &format!("{}", Bytes::new(62500)), + "62.50 kB" + ); + + assert_eq!( + &format!("{}", Bytes::new(329990)), + "329.99 kB" + ); + } + + #[test] + fn megabytes () { + assert_eq!( + &format!("{}", Bytes::new(2750000)), + "2.75 MB" + ); + + assert_eq!( + &format!("{}", Bytes::new(55000000)), + "55.00 MB" + ); + + assert_eq!( + &format!("{}", Bytes::new(987654321)), + "987.65 MB" + ); + } + + #[test] + fn gigabytes () { + assert_eq!( + &format!("{}", Bytes::new(5280000000)), + "5.28 GB" + ); + + assert_eq!( + &format!("{}", Bytes::new(95200000000)), + "95.20 GB" + ); + + assert_eq!( + &format!("{}", Bytes::new(302000000000)), + "302.00 GB" + ); + } +} + // #[cfg(test)] // mod cli { // use super::*;