test(tvix/eval): add test for total_fmt_float

Change-Id: If6c478ee3d2e4ecf5ef92289614f86535ad05cb7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7927
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
Florian Klink 2023-01-25 12:16:55 +01:00 committed by clbot
parent 164005656d
commit 669496f0ba

View file

@ -656,6 +656,34 @@ mod tests {
use super::*;
use imbl::vector;
mod floats {
use crate::value::total_fmt_float;
#[test]
fn format_float() {
let ff = vec![
(0f64, "0"),
(1.0f64, "1"),
(-0.01, "-0.01"),
(5e+22, "5e+22"),
(1e6, "1e+06"),
(-2E-2, "-0.02"),
(6.626e-34, "6.626e-34"),
(9_224_617.445_991_228_313, "9.22462e+06"),
];
for (n, expected) in ff.iter() {
let mut buf = String::new();
let res = total_fmt_float(*n, &mut buf);
assert!(res.is_ok());
assert_eq!(
expected, &buf,
"{} should be formatted as {}, but got {}",
n, expected, &buf
);
}
}
}
mod nix_eq {
use crate::observer::NoOpObserver;