/* ==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==-- KiB Copyright (C) 2016-2017, 2019-2020, 2022, 2024 Anonymous There are several releases over multiple years, they are listed as ranges, such as: "2016-2017". This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . ::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::-- */ extern crate kib; use kib::{fmt, KIB, MIB, GIB, TIB, PIB, EIB, ZIB, YIB}; #[test] fn units() { let one_kib: u128 = 1024; assert_eq!(one_kib, KIB.into()); assert_eq!(one_kib.pow(2), MIB.into()); assert_eq!(one_kib.pow(3), GIB.into()); assert_eq!(one_kib.pow(4), TIB.into()); assert_eq!(one_kib.pow(5), PIB.into()); assert_eq!(one_kib.pow(6), EIB.into()); assert_eq!(one_kib.pow(7), ZIB); assert_eq!(one_kib.pow(8), YIB); assert_eq!(one_kib.pow(9), YIB * 1024_u128); assert_eq!(one_kib.pow(10), YIB * 1024_u128.pow(2)); assert_eq!(one_kib.pow(11), YIB * 1024_u128.pow(3)); } #[test] fn formats() { assert_eq!(fmt(1023_u16), "1023 Bytes"); assert_eq!(fmt(KIB), "1.00 KiB"); assert_eq!(fmt(MIB), "1.00 MiB"); assert_eq!(fmt(GIB), "1.00 GiB"); assert_eq!(fmt(TIB), "1.00 TiB"); assert_eq!(fmt(PIB), "1.00 PiB"); assert_eq!(fmt(EIB), "1.00 EiB"); assert_eq!(fmt(ZIB), "1.00 ZiB"); assert_eq!(fmt(YIB), "1.00 YiB"); assert_eq!(fmt(YIB * 1024), "1024.00 YiB"); assert_eq!(fmt(YIB * 1024_u128.pow(2)), "1048576.00 YiB"); assert_eq!(fmt(YIB * 1024_u128.pow(3)), "1073741824.00 YiB"); }