Fix to a minor fumble over SI prefixes, some internal refactoring, and minor API additions.
- Added new function max() to byteunit type. - New public constant 'simplebyteunit::MAX' defining the maximum supported power. - Output module to house arithmetic and prefix functions for output values. - For the sake of SI compliance, kilobytes are now prefixed as 'kB'.
This commit is contained in:
parent
e4204d588e
commit
7d182d860b
5 changed files with 87 additions and 67 deletions
10
src/test.rs
10
src/test.rs
|
@ -39,8 +39,8 @@ fn format_all() {
|
|||
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!(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");
|
||||
|
@ -73,8 +73,8 @@ fn bytes() {
|
|||
fn k() {
|
||||
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]
|
||||
|
@ -147,7 +147,7 @@ fn add() {
|
|||
let b = ByteUnit::SI(POSITIVE_5B);
|
||||
let division = a + b;
|
||||
|
||||
assert_eq!(division.to_string(), "10.00 KB");
|
||||
assert_eq!(division.to_string(), "10.00 kB");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue