This repository has been archived on 2024-10-16. You can view files and clone it, but cannot push or open issues or pull requests.
pt/members/libpt-bintols/tests/display.rs

71 lines
2.3 KiB
Rust
Raw Normal View History

2023-09-29 18:24:19 +02:00
use libpt_bintols::display::*;
2024-01-10 21:52:13 +01:00
use libpt_bintols::*;
2023-09-20 18:16:21 +02:00
#[test]
fn btobin() {
let data = [19, 19];
let r = bytes_to_bin(&data);
assert_eq!(r, format!("0b00010011_00010011"));
2024-03-03 17:16:50 +01:00
let data = [0xff, 0xff];
let r = bytes_to_bin(&data);
assert_eq!(r, format!("0b11111111_11111111"));
2023-09-20 18:16:21 +02:00
}
#[test]
fn big_btobin() {
2024-01-10 21:52:13 +01:00
let data = [12, 31, 82, 32, 123, 32, 92, 23, 12, 32, 12, 1, 1, 1];
2023-09-20 18:16:21 +02:00
let r = bytes_to_bin(&data);
2024-01-10 21:52:13 +01:00
assert_eq!(
r,
format!(
2024-03-03 17:16:50 +01:00
"0b00001100_00011111_01010010_00100000_01111011_00100000_01011100_00010111_00001100_00100000_00001100_00000001_00000001_00000001"
2024-01-10 21:52:13 +01:00
)
);
2023-09-20 18:16:21 +02:00
}
#[test]
fn bybit() {
assert_eq!(byte_bit_display(120), format!("120 B = 960 bit"));
assert_eq!(byte_bit_display(12), format!("12 B = 96 bit"));
assert_eq!(byte_bit_display(8), format!("8 B = 64 bit"));
}
#[test]
fn hmnbytes() {
2024-01-10 21:52:13 +01:00
assert_eq!(humanbytes(0), format!("0 B"));
assert_eq!(humanbytes(1), format!("1 B"));
2023-09-20 18:16:21 +02:00
2024-01-10 21:52:13 +01:00
assert_eq!(humanbytes(KIBI - 1), format!("1023 B"));
assert_eq!(humanbytes(KIBI), format!("1.00 K"));
assert_eq!(humanbytes(KIBI + 1), format!("1.00 K"));
2023-09-20 18:16:21 +02:00
2024-01-10 21:52:13 +01:00
assert_eq!(humanbytes(MEBI - 1), format!("1024.00 K"));
assert_eq!(humanbytes(MEBI), format!("1.00 M"));
assert_eq!(humanbytes(MEBI + 1), format!("1.00 M"));
2023-09-20 18:16:21 +02:00
2024-01-10 21:52:13 +01:00
assert_eq!(humanbytes(GIBI - 1), format!("1024.00 M"));
assert_eq!(humanbytes(GIBI), format!("1.00 G"));
assert_eq!(humanbytes(GIBI + 1), format!("1.00 G"));
2023-09-20 18:16:21 +02:00
2024-01-10 21:52:13 +01:00
assert_eq!(humanbytes(TEBI - 1), format!("1024.00 G"));
assert_eq!(humanbytes(TEBI), format!("1.00 T"));
assert_eq!(humanbytes(TEBI + 1), format!("1.00 T"));
2023-09-20 18:16:21 +02:00
2024-01-10 21:52:13 +01:00
assert_eq!(humanbytes(PEBI - 1), format!("1024.00 T"));
assert_eq!(humanbytes(PEBI), format!("1.00 P"));
assert_eq!(humanbytes(PEBI + 1), format!("1.00 P"));
2023-09-20 18:16:21 +02:00
2024-01-10 21:52:13 +01:00
assert_eq!(humanbytes(EXBI - 1), format!("1024.00 P"));
assert_eq!(humanbytes(EXBI), format!("1.00 E"));
assert_eq!(humanbytes(EXBI + 1), format!("1.00 E"));
2023-09-20 18:16:21 +02:00
2024-01-10 21:52:13 +01:00
assert_eq!(humanbytes(ZEBI - 1), format!("1024.00 E"));
assert_eq!(humanbytes(ZEBI), format!("1.00 Z"));
assert_eq!(humanbytes(ZEBI + 1), format!("1.00 Z"));
2023-09-20 18:16:21 +02:00
2024-01-10 21:52:13 +01:00
assert_eq!(humanbytes(YOBI - 1), format!("1024.00 Z"));
assert_eq!(humanbytes(YOBI), format!("1.00 Y"));
assert_eq!(humanbytes(YOBI + 1), format!("1.00 Y"));
2023-09-20 18:16:21 +02:00
}