Display bandwidth in different unit families#328
Conversation
- Supported units are {binary,SI}-{bytes,bits}
4c3ff3e to
43fd508
Compare
|
Ok I tried to add some tests via a pr to your branch but I failed miserably , can you add this please, also I have some couple remarks there as well mod tests {
use crate::display::BandwidthUnitFamily;
#[test]
fn unit_test() {
// size < 1024 are not calculated correctly
{
let size = 1024.;
assert_eq!(
BandwidthUnitFamily::BinBytes.get_unit_for(size),
(1024., "KiB")
);
assert_eq!(
BandwidthUnitFamily::BinBits.get_unit_for(size),
(128., "Kib")
);
// the next 2 `k` are lowercase
// should they be uppercase ?
// they are uppercase on the next units (M G T)
assert_eq!(
BandwidthUnitFamily::SiBytes.get_unit_for(size),
(1000., "kB")
);
assert_eq!(BandwidthUnitFamily::SiBits.get_unit_for(size), (125., "kb"));
}
{
let size = 1024. * 1024.;
assert_eq!(
BandwidthUnitFamily::BinBytes.get_unit_for(size),
(1048576.0, "MiB")
);
assert_eq!(
BandwidthUnitFamily::BinBits.get_unit_for(size),
(131072.0, "Mib")
);
assert_eq!(
BandwidthUnitFamily::SiBytes.get_unit_for(size),
(1000000.0, "MB")
);
assert_eq!(
BandwidthUnitFamily::SiBits.get_unit_for(size),
(125000.0, "Mb")
);
}
{
let size = 1024. * 1024. * 1024.;
assert_eq!(
BandwidthUnitFamily::BinBytes.get_unit_for(size),
(1073741824.0, "GiB")
);
assert_eq!(
BandwidthUnitFamily::BinBits.get_unit_for(size),
(134217728.0, "Gib")
);
assert_eq!(
BandwidthUnitFamily::SiBytes.get_unit_for(size),
(1000000000.0, "GB")
);
assert_eq!(
BandwidthUnitFamily::SiBits.get_unit_for(size),
(125000000.0, "Gb")
);
}
{
let size = 1024. * 1024. * 1024. * 1024.;
assert_eq!(
BandwidthUnitFamily::BinBytes.get_unit_for(size),
(1099511627776.0, "TiB")
);
assert_eq!(
BandwidthUnitFamily::BinBits.get_unit_for(size),
(137438953472.0, "Tib")
);
assert_eq!(
BandwidthUnitFamily::SiBytes.get_unit_for(size),
(1000000000000.0, "TB")
);
assert_eq!(
BandwidthUnitFamily::SiBits.get_unit_for(size),
(125000000000.0, "Tb")
);
}
}
} |
|
Ah okay. Yeah a unit test will do. I was overcomplicating the situation thinking I need an integration test. I used some itertools magic to test a wider variety of values. Now I can finally see the appeal of
Nope. The |
|
Also I took a look at the test cases |
|
Ah I see, I was misunderstanding what |
|
Okay then. Let's get this merged! |
-u,--unit-familyCloses #145; closes #213.
Checklist