diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..209b16b --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,16 @@ +unstable_features = true +indent_style = "Block" +imports_indent = "Block" +imports_layout = "HorizontalVertical" +imports_granularity = "Crate" +brace_style = "PreferSameLine" +match_arm_leading_pipes = "Never" +match_arm_blocks = false +condense_wildcard_suffixes = true +overflow_delimited_expr = false +spaces_around_ranges = true +reorder_imports = true +hard_tabs = false +max_width = 130 +fn_call_width = 120 +chain_width = 90 diff --git a/src/input.rs b/src/input.rs index 051d7e9..f082103 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,8 +1,8 @@ -/* +/* * SimpleByteUnit - * + * * Copyright (C) 2023-2025 Xavier Moffett - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -27,20 +27,23 @@ pub fn parse(s: &str) -> Result<(f64, f64, i8, bool), Error> { string if string.ends_with("pb") => ("pb", P, false), string if string.ends_with("eb") => ("eb", E, false), string if string.ends_with("b") => ("b", B, false), - _ => Err(Error::InvalidUnit(format!("'{s}' contains no supported nor valid byteunits.")))? + _ => Err(Error::InvalidUnit(format!("'{s}' contains no supported nor valid byteunits.")))?, + }; + let s = s.to_lowercase().replace(v.0, "").replace(" ", ""); + let multiplier = match v.2 { + true => 1024.0, + false => 1000.0, }; - let s = s.to_lowercase() - .replace(v.0, "") - .replace(" ", ""); - let multiplier = match v.2 { true => 1024.0, false => 1000.0 }; match s.parse() { Ok(val) => Ok((val, multiplier, v.1, v.2)), - Err(_) => Err(Error::ErroroneousInput(format!("'{s}' contains an invalid float or integer value."))) + Err(_) => Err(Error::ErroroneousInput(format!("'{s}' contains an invalid float or integer value."))), } } -pub fn arithmetic(input: (f64, f64, i8, bool)) -> (bool, T) where T: From { +pub fn arithmetic(input: (f64, f64, i8, bool)) -> (bool, T) +where + T: From, { let iec = input.3; let power_of = input.2; let multiplier = input.1; diff --git a/src/lib.rs b/src/lib.rs index 7e7a206..27fdaaa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ -/* +/* * SimpleByteUnit - * + * * Copyright (C) 2023-2025 Xavier Moffett - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,7 +24,7 @@ simplebyteunit = "0.2.0" ## Example -Generate a human-readable, formatted ByteUnit: +Generate a human-readable, formatted ByteUnit: ```rust use simplebyteunit::simplebyteunit::*; diff --git a/src/output.rs b/src/output.rs index 29a18fb..687448b 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,8 +1,8 @@ -/* +/* * SimpleByteUnit - * + * * Copyright (C) 2023-2025 Xavier Moffett - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,7 +21,7 @@ pub fn prefix<'a, T: Copy>(unit: &ByteUnit, i: i8) -> &'a str { T => "TiB", P => "PiB", E => "EiB", - _ => "B" + _ => "B", }, ByteUnit::SI(_) => match i { K => "kB", @@ -30,22 +30,27 @@ pub fn prefix<'a, T: Copy>(unit: &ByteUnit, i: i8) -> &'a str { T => "TB", P => "PB", E => "EB", - _ => "B" - } + _ => "B", + }, } } -pub fn arithmetic(value: (T, f64), power_of: i8) -> (i8, f64) where i64: From { - let bytes: i64 = value.0.into(); - let diviser = value.1; +pub fn arithmetic(value: (T, f64), power_of: i8) -> (i8, f64) +where + i64: From, { + let bytes: i64 = value.0.into(); + let diviser = value.1; let positive = bytes > -1; let mut bytes: f64 = if positive { bytes } else { -bytes } as f64; let mut power = 0; while bytes >= diviser && power < power_of { - bytes /= diviser; + bytes /= diviser; power += 1; } - - match positive { true => (power, bytes), false => (power, -bytes) } + + match positive { + true => (power, bytes), + false => (power, -bytes), + } } diff --git a/src/simplebyteunit.rs b/src/simplebyteunit.rs index 475978a..d7c1945 100644 --- a/src/simplebyteunit.rs +++ b/src/simplebyteunit.rs @@ -1,8 +1,8 @@ -/* +/* * SimpleByteUnit * * Copyright (C) 2023-2025 Xavier Moffett - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -10,15 +10,18 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -/*! +/*! Fast, stupid simple ByteUnit implementation Provides a simple way to encapsulate primitives as byteunits. */ -use std::{fmt::{Display, Formatter, Debug}, - ops::{Mul, Div, Add, Sub}, str::FromStr}; use crate::{input, output}; +use std::{ + fmt::{Debug, Display, Formatter}, + ops::{Add, Div, Mul, Sub}, + str::FromStr, +}; /// IEC ByteUnit (x*1024) pub const IEC: ByteUnit<()> = ByteUnit::IEC(()); @@ -36,12 +39,12 @@ pub const G: i8 = 3; pub const M: i8 = 2; /// Power of 1 (Kilo/Kibi) pub const K: i8 = 1; -/// Base unit +/// Base unit pub const B: i8 = 0; /// Maximum supported power pub const MAX: i8 = E; -/// Thin encapsulate of a supported, primitive integer to provide simple byteunit facilities +/// Thin encapsulate of a supported, primitive integer to provide simple byteunit facilities pub enum ByteUnit { IEC(T), SI(T), @@ -58,45 +61,58 @@ pub trait ToByteUnit { fn to_byteunit(self, byte: ByteUnit<()>) -> ByteUnit; } -impl ToByteUnit for u32 where i64: From { +impl ToByteUnit for u32 +where + i64: From, +{ fn to_byteunit(self, unit: ByteUnit<()>) -> ByteUnit { match unit { ByteUnit::IEC(()) => ByteUnit::IEC(self), ByteUnit::SI(()) => ByteUnit::SI(self), - } + } } } -impl ToByteUnit for i32 where i64: From { +impl ToByteUnit for i32 +where + i64: From, +{ fn to_byteunit(self, unit: ByteUnit<()>) -> ByteUnit { match unit { ByteUnit::IEC(()) => ByteUnit::IEC(self), ByteUnit::SI(()) => ByteUnit::SI(self), - } + } } } -impl ToByteUnit for i64 where i64: From { +impl ToByteUnit for i64 +where + i64: From, +{ fn to_byteunit(self, unit: ByteUnit<()>) -> ByteUnit { match unit { ByteUnit::IEC(()) => ByteUnit::IEC(self), ByteUnit::SI(()) => ByteUnit::SI(self), - } + } } } -impl ByteUnit where i64: From, T: Copy { +impl ByteUnit +where + i64: From, + T: Copy, +{ fn value(&self) -> (T, f64) { match self { - Self::IEC(val) => (*val, 1024.0), - Self::SI(val) => (*val, 1000.0) + Self::IEC(val) => (*val, 1024.0), + Self::SI(val) => (*val, 1000.0), } } fn format(&self, arithmetic: (i8, f64)) -> String { let power = arithmetic.0; let value = arithmetic.1; - + match power { B => format!("{:.0} {}", value, output::prefix(self, power)), _ => format!("{:.2} {}", value, output::prefix(self, power)), @@ -105,10 +121,10 @@ impl ByteUnit where i64: From, T: Copy { /// Acquire and return base value of encapsulated primitive pub fn val(&self) -> T { - match self { - Self::IEC(val) => *val, + match self { + Self::IEC(val) => *val, Self::SI(val) => *val, - } + } } /// Returns a formatted string with up-to a maximum supported power. @@ -121,7 +137,7 @@ impl ByteUnit where i64: From, T: Copy { self.format(output::arithmetic(self.value(), power_of)) } - /// Returns a formatted string with a maximum power of 1 (Kilo/Kibi) + /// Returns a formatted string with a maximum power of 1 (Kilo/Kibi) pub fn k(&self) -> String { self.format(output::arithmetic(self.value(), K)) } @@ -131,17 +147,17 @@ impl ByteUnit where i64: From, T: Copy { self.format(output::arithmetic(self.value(), M)) } - /// Returns a formatted string with a maximum power of 3 (Giga/Gibi) + /// Returns a formatted string with a maximum power of 3 (Giga/Gibi) pub fn g(&self) -> String { self.format(output::arithmetic(self.value(), G)) } - /// Returns a formatted string with a maximum power of 4 (Tera/Tebi) + /// Returns a formatted string with a maximum power of 4 (Tera/Tebi) pub fn p(&self) -> String { self.format(output::arithmetic(self.value(), P)) } - /// Returns a formatted string with a maximum power of 5 (Peta/Pebi) + /// Returns a formatted string with a maximum power of 5 (Peta/Pebi) pub fn t(&self) -> String { self.format(output::arithmetic(self.value(), T)) } @@ -153,8 +169,12 @@ impl ByteUnit where i64: From, T: Copy { } /// Display implementation with a maximum power of 6 (Exa/Exbi) -impl Display for ByteUnit where i64: From, T: Copy { - fn fmt(&self, f:&mut Formatter<'_>) -> std::fmt::Result { +impl Display for ByteUnit +where + i64: From, + T: Copy, +{ + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let arithmetic = output::arithmetic(self.value(), MAX); let bytes = arithmetic.1; let index = arithmetic.0; @@ -167,8 +187,12 @@ impl Display for ByteUnit where i64: From, T: Copy { } /// Debug implementation with a maximum power of 6 (Exa/Exbi) -impl Debug for ByteUnit where i64: From, T: Copy { - fn fmt(&self, f:&mut Formatter<'_>) -> std::fmt::Result { +impl Debug for ByteUnit +where + i64: From, + T: Copy, +{ + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let arithmetic = output::arithmetic(self.value(), MAX); let bytes = arithmetic.1; let index = arithmetic.0; @@ -180,26 +204,42 @@ impl Debug for ByteUnit where i64: From, T: Copy { } } -impl From<&str> for ByteUnit where i64: From, T: Copy, T: From { +impl From<&str> for ByteUnit +where + i64: From, + T: Copy, + T: From, +{ fn from(value: &str) -> Self { ByteUnit::from_str(value).unwrap() } } -impl FromStr for ByteUnit where i64: From, T: Copy, i64: From, T: From { +impl FromStr for ByteUnit +where + i64: From, + T: Copy, + i64: From, + T: From, +{ type Err = Error; fn from_str(s: &str) -> Result { let input = input::arithmetic::(input::parse(s)?); match input.0 { - true => Ok(ByteUnit::IEC(input.1)), false => Ok(ByteUnit::SI(input.1)) + true => Ok(ByteUnit::IEC(input.1)), + false => Ok(ByteUnit::SI(input.1)), } } } -impl PartialOrd for ByteUnit where i64: From, T: Copy + PartialEq { - fn partial_cmp(&self, other: &Self) -> Option { +impl PartialOrd for ByteUnit +where + i64: From, + T: Copy + PartialEq, +{ + fn partial_cmp(&self, other: &Self) -> Option { let value = i64::from(self.val()); let other = i64::from(other.val()); @@ -207,15 +247,23 @@ impl PartialOrd for ByteUnit where i64: From, T: Copy + PartialEq { } } -impl PartialEq for ByteUnit where i64: From, T: Copy + PartialEq { - fn eq(&self, other: &Self) -> bool { +impl PartialEq for ByteUnit +where + i64: From, + T: Copy + PartialEq, +{ + fn eq(&self, other: &Self) -> bool { other.val().eq(&self.val()) } } -impl Add for ByteUnit where i64: From, T: Copy + Add { +impl Add for ByteUnit +where + i64: From, + T: Copy + Add, +{ type Output = Self; - + fn add(self, input: Self) -> Self::Output { match self { Self::IEC(value) => Self::IEC(value + input.val()), @@ -224,9 +272,13 @@ impl Add for ByteUnit where i64: From, T: Copy + Add { } } -impl Sub for ByteUnit where i64: From, T: Copy + Sub { +impl Sub for ByteUnit +where + i64: From, + T: Copy + Sub, +{ type Output = Self; - + fn sub(self, input: Self) -> Self::Output { match self { Self::IEC(value) => Self::IEC(value - input.val()), @@ -235,9 +287,13 @@ impl Sub for ByteUnit where i64: From, T: Copy + Sub { } } -impl Mul for ByteUnit where i64: From, T: Copy + Mul { +impl Mul for ByteUnit +where + i64: From, + T: Copy + Mul, +{ type Output = Self; - + fn mul(self, input: Self) -> Self::Output { match self { Self::IEC(value) => Self::IEC(value * input.val()), @@ -246,9 +302,13 @@ impl Mul for ByteUnit where i64: From, T: Copy + Mul { } } -impl Div for ByteUnit where i64: From, T: Copy + Div { +impl Div for ByteUnit +where + i64: From, + T: Copy + Div, +{ type Output = Self; - + fn div(self, input: Self) -> Self::Output { match self { Self::IEC(value) => Self::IEC(value / input.val()), diff --git a/tests/integration.rs b/tests/integration.rs index 922e687..78b3ef2 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -1,8 +1,8 @@ -/* +/* * SimpleByteUnit * * Copyright (C) 2023-2025 Xavier Moffett - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -10,12 +10,11 @@ * http://www.apache.org/licenses/LICENSE-2.0 */ -use simplebyteunit::simplebyteunit::*; -use simplebyteunit::simplebyteunit::ToByteUnit; +use simplebyteunit::simplebyteunit::{ToByteUnit, *}; const POSITIVE_5B: i64 = 5000; -const NEGATIVE_5B: i64 = -5000; -const POSITIVE_5K: i64 = 5000000; +const NEGATIVE_5B: i64 = -5000; +const POSITIVE_5K: i64 = 5000000; const NEGATIVE_5K: i64 = -5000000; const POSITIVE_5G: i64 = 5000000000; const NEGATIVE_5G: i64 = -5000000000; @@ -28,52 +27,51 @@ const NEGATIVE_5E: i64 = -5000000000000000000; #[test] fn format_all() { - assert_eq!(NEGATIVE_5E.to_byteunit(SI).to_string(), "-5.00 EB"); - assert_eq!(POSITIVE_5E.to_byteunit(SI).to_string(), "5.00 EB"); - assert_eq!(NEGATIVE_5P.to_byteunit(SI).to_string(), "-5.00 PB"); - assert_eq!(POSITIVE_5P.to_byteunit(SI).to_string(), "5.00 PB"); - assert_eq!(NEGATIVE_5T.to_byteunit(SI).to_string(), "-5.00 TB"); - assert_eq!(POSITIVE_5T.to_byteunit(SI).to_string(), "5.00 TB"); - assert_eq!(NEGATIVE_5G.to_byteunit(SI).to_string(), "-5.00 GB"); - assert_eq!(POSITIVE_5G.to_byteunit(SI).to_string(), "5.00 GB"); - assert_eq!(POSITIVE_5K.to_byteunit(SI).to_string(), "5.00 MB"); - assert_eq!(NEGATIVE_5K.to_byteunit(SI).to_string(), "-5.00 MB"); + assert_eq!(NEGATIVE_5E.to_byteunit(SI).to_string(), "-5.00 EB"); + assert_eq!(POSITIVE_5E.to_byteunit(SI).to_string(), "5.00 EB"); + assert_eq!(NEGATIVE_5P.to_byteunit(SI).to_string(), "-5.00 PB"); + assert_eq!(POSITIVE_5P.to_byteunit(SI).to_string(), "5.00 PB"); + assert_eq!(NEGATIVE_5T.to_byteunit(SI).to_string(), "-5.00 TB"); + assert_eq!(POSITIVE_5T.to_byteunit(SI).to_string(), "5.00 TB"); + assert_eq!(NEGATIVE_5G.to_byteunit(SI).to_string(), "-5.00 GB"); + assert_eq!(POSITIVE_5G.to_byteunit(SI).to_string(), "5.00 GB"); + assert_eq!(POSITIVE_5K.to_byteunit(SI).to_string(), "5.00 MB"); + assert_eq!(NEGATIVE_5K.to_byteunit(SI).to_string(), "-5.00 MB"); assert_eq!(POSITIVE_5B.to_byteunit(SI).to_string(), "5.00 kB"); assert_eq!(NEGATIVE_5B.to_byteunit(SI).to_string(), "-5.00 kB"); - assert_eq!(NEGATIVE_5E.to_byteunit(IEC).to_string(), "-4.34 EiB"); - assert_eq!(POSITIVE_5E.to_byteunit(IEC).to_string(), "4.34 EiB"); - assert_eq!(NEGATIVE_5P.to_byteunit(IEC).to_string(), "-4.44 PiB"); - assert_eq!(POSITIVE_5P.to_byteunit(IEC).to_string(), "4.44 PiB"); + assert_eq!(NEGATIVE_5E.to_byteunit(IEC).to_string(), "-4.34 EiB"); + assert_eq!(POSITIVE_5E.to_byteunit(IEC).to_string(), "4.34 EiB"); + assert_eq!(NEGATIVE_5P.to_byteunit(IEC).to_string(), "-4.44 PiB"); + assert_eq!(POSITIVE_5P.to_byteunit(IEC).to_string(), "4.44 PiB"); assert_eq!(NEGATIVE_5T.to_byteunit(IEC).to_string(), "-4.55 TiB"); - assert_eq!(NEGATIVE_5T.to_byteunit(IEC).to_string(), "-4.55 TiB"); - assert_eq!(POSITIVE_5T.to_byteunit(IEC).to_string(), "4.55 TiB"); - assert_eq!(NEGATIVE_5G.to_byteunit(IEC).to_string(), "-4.66 GiB"); - assert_eq!(POSITIVE_5G.to_byteunit(IEC).to_string(), "4.66 GiB"); - assert_eq!(POSITIVE_5K.to_byteunit(IEC).to_string(), "4.77 MiB"); - assert_eq!(NEGATIVE_5K.to_byteunit(IEC).to_string(), "-4.77 MiB"); + assert_eq!(NEGATIVE_5T.to_byteunit(IEC).to_string(), "-4.55 TiB"); + assert_eq!(POSITIVE_5T.to_byteunit(IEC).to_string(), "4.55 TiB"); + assert_eq!(NEGATIVE_5G.to_byteunit(IEC).to_string(), "-4.66 GiB"); + assert_eq!(POSITIVE_5G.to_byteunit(IEC).to_string(), "4.66 GiB"); + assert_eq!(POSITIVE_5K.to_byteunit(IEC).to_string(), "4.77 MiB"); + assert_eq!(NEGATIVE_5K.to_byteunit(IEC).to_string(), "-4.77 MiB"); assert_eq!(POSITIVE_5B.to_byteunit(IEC).to_string(), "4.88 KiB"); assert_eq!(NEGATIVE_5B.to_byteunit(IEC).to_string(), "-4.88 KiB"); - } #[test] fn bytes() { - assert_eq!(NEGATIVE_5B.to_byteunit(IEC).pow(B), "-5000 B"); - assert_eq!(NEGATIVE_5B.to_byteunit(SI).pow(B), "-5000 B"); - assert_eq!(POSITIVE_5B.to_byteunit(IEC).pow(B), "5000 B"); - assert_eq!(POSITIVE_5B.to_byteunit(SI).pow(B), "5000 B"); - assert_eq!(NEGATIVE_5E.to_byteunit(IEC).pow(B), "-5000000000000000000 B"); - assert_eq!(NEGATIVE_5E.to_byteunit(SI).pow(B), "-5000000000000000000 B"); - assert_eq!(POSITIVE_5E.to_byteunit(IEC).pow(B), "5000000000000000000 B"); - assert_eq!(POSITIVE_5E.to_byteunit(SI).pow(B), "5000000000000000000 B"); + assert_eq!(NEGATIVE_5B.to_byteunit(IEC).pow(B), "-5000 B"); + assert_eq!(NEGATIVE_5B.to_byteunit(SI).pow(B), "-5000 B"); + assert_eq!(POSITIVE_5B.to_byteunit(IEC).pow(B), "5000 B"); + assert_eq!(POSITIVE_5B.to_byteunit(SI).pow(B), "5000 B"); + assert_eq!(NEGATIVE_5E.to_byteunit(IEC).pow(B), "-5000000000000000000 B"); + assert_eq!(NEGATIVE_5E.to_byteunit(SI).pow(B), "-5000000000000000000 B"); + assert_eq!(POSITIVE_5E.to_byteunit(IEC).pow(B), "5000000000000000000 B"); + assert_eq!(POSITIVE_5E.to_byteunit(SI).pow(B), "5000000000000000000 B"); } #[test] fn k() { - assert_eq!(NEGATIVE_5K.to_byteunit(IEC).pow(K), "-4882.81 KiB"); + assert_eq!(NEGATIVE_5K.to_byteunit(IEC).pow(K), "-4882.81 KiB"); assert_eq!(POSITIVE_5K.to_byteunit(IEC).pow(K), "4882.81 KiB"); - assert_eq!(NEGATIVE_5K.to_byteunit(SI).pow(K), "-5000.00 kB"); - assert_eq!(POSITIVE_5K.to_byteunit(SI).pow(K), "5000.00 kB"); + assert_eq!(NEGATIVE_5K.to_byteunit(SI).pow(K), "-5000.00 kB"); + assert_eq!(POSITIVE_5K.to_byteunit(SI).pow(K), "5000.00 kB"); } #[test] @@ -87,9 +85,9 @@ fn m() { #[test] fn g() { assert_eq!(NEGATIVE_5T.to_byteunit(IEC).pow(G), "-4656.61 GiB"); - assert_eq!(POSITIVE_5T.to_byteunit(IEC).pow(G), "4656.61 GiB"); + assert_eq!(POSITIVE_5T.to_byteunit(IEC).pow(G), "4656.61 GiB"); assert_eq!(NEGATIVE_5T.to_byteunit(SI).pow(G), "-5000.00 GB"); - assert_eq!(POSITIVE_5T.to_byteunit(SI).pow(G), "5000.00 GB"); + assert_eq!(POSITIVE_5T.to_byteunit(SI).pow(G), "5000.00 GB"); } #[test] @@ -102,24 +100,24 @@ fn t() { #[test] fn p() { - assert_eq!(NEGATIVE_5E.to_byteunit(IEC).pow(P), "-4440.89 PiB"); - assert_eq!(POSITIVE_5E.to_byteunit(IEC).pow(P), "4440.89 PiB"); - assert_eq!(NEGATIVE_5E.to_byteunit(SI).pow(P), "-5000.00 PB"); - assert_eq!(POSITIVE_5E.to_byteunit(SI).pow(P), "5000.00 PB"); + assert_eq!(NEGATIVE_5E.to_byteunit(IEC).pow(P), "-4440.89 PiB"); + assert_eq!(POSITIVE_5E.to_byteunit(IEC).pow(P), "4440.89 PiB"); + assert_eq!(NEGATIVE_5E.to_byteunit(SI).pow(P), "-5000.00 PB"); + assert_eq!(POSITIVE_5E.to_byteunit(SI).pow(P), "5000.00 PB"); } #[test] fn e() { - assert_eq!(NEGATIVE_5E.to_byteunit(IEC).pow(E), "-4.34 EiB"); - assert_eq!(POSITIVE_5E.to_byteunit(IEC).pow(E), "4.34 EiB"); - assert_eq!(NEGATIVE_5E.to_byteunit(SI).pow(E), "-5.00 EB"); - assert_eq!(POSITIVE_5E.to_byteunit(SI).pow(E), "5.00 EB"); + assert_eq!(NEGATIVE_5E.to_byteunit(IEC).pow(E), "-4.34 EiB"); + assert_eq!(POSITIVE_5E.to_byteunit(IEC).pow(E), "4.34 EiB"); + assert_eq!(NEGATIVE_5E.to_byteunit(SI).pow(E), "-5.00 EB"); + assert_eq!(POSITIVE_5E.to_byteunit(SI).pow(E), "5.00 EB"); } #[test] fn eq() { - assert_eq!(POSITIVE_5G.to_byteunit(SI) == POSITIVE_5G.to_byteunit(SI), true); - assert_eq!(POSITIVE_5B.to_byteunit(SI) == POSITIVE_5G.to_byteunit(SI), false); + assert_eq!(POSITIVE_5G.to_byteunit(SI) == POSITIVE_5G.to_byteunit(SI), true); + assert_eq!(POSITIVE_5B.to_byteunit(SI) == POSITIVE_5G.to_byteunit(SI), false); } #[test] @@ -156,7 +154,6 @@ fn sub() { let division = a - b; assert_eq!(division.to_string(), "0 B"); - } #[test]