Debian Codegraph @

src/tests.rs

raw symbols SCIP
1 #[cfg(not(feature = "si-units"))]
2 mod decimal {
3 use crate::human_bytes;
4
5 #[test]
6 fn nothing() {
7 assert_eq!(human_bytes(0_u32), "0 B".to_string());
8 }
9
10 #[test]
11 fn bytes() {
12 assert_eq!(human_bytes(550_u32), "550 B".to_string());
13 }
14 #[test]
15 fn kilobytes() {
16 assert_eq!(human_bytes(550_000_u32), "550 KB".to_string());
17 }
18
19 #[test]
20 fn megabytes() {
21 assert_eq!(human_bytes(650_000_000_u32), "650 MB".to_string());
22 }
23
24 #[test]
25 fn gigabytes() {
26 assert_eq!(
27 human_bytes(15_300_000_000_u64 as f64),
28 "15.3 GB".to_string()
29 );
30 }
31
32 #[test]
33 fn terabytes() {
34 assert_eq!(human_bytes(2_500_000_000_000_u64 as f64), "2.5 TB");
35 }
36 }
37
38 #[cfg(feature = "si-units")]
39 mod binary {
40 use crate::human_bytes;
41
42 #[test]
43 fn nothing() {
44 assert_eq!(human_bytes(0_u32), "0 B".to_string());
45 }
46
47 #[test]
48 fn bytes() {
49 assert_eq!(human_bytes(550_u32), "550 B".to_string());
50 }
51 #[test]
52 fn kibibytes() {
53 assert_eq!(human_bytes(563_200_u32), "550 KiB".to_string());
54 }
55
56 #[test]
57 fn mebibytes() {
58 assert_eq!(human_bytes(681_574_400_u32), "650 MiB".to_string());
59 }
60
61 #[test]
62 fn gibibytes() {
63 assert_eq!(
64 human_bytes(16_428_249_907_u64 as f64),
65 "15.3 GiB".to_string()
66 );
67 }
68
69 #[test]
70 fn tebibytes() {
71 // Hacky, I know, but easier to write ;)
72 let tebibyte: u64 = 2_u64.pow(40);
73 assert_eq!(
74 human_bytes(((tebibyte * 2) + (tebibyte / 2)) as f64),
75 "2.5 TiB"
76 );
77 }
78 }