From 669496f0ba4924b19c911220b9290aa45db9f89c Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 25 Jan 2023 12:16:55 +0100 Subject: 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 Autosubmit: flokli --- tvix/eval/src/value/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tvix/eval/src/value') diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 12b3592e1625..0f515109f5c7 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -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; -- cgit 1.4.1