Debian Codegraph @

src/tests/float.rs

raw symbols SCIP
1 use std::collections::HashMap;
2 use {FmtError, Format};
3
4 #[test]
5 fn test_fmt_float64() -> Result<(), FmtError> {
6 let mut vars: HashMap<String, f64> = HashMap::new();
7 vars.insert("Zero".to_string(), 0.0);
8 vars.insert("Three".to_string(), 10.0 / 3.0);
9 vars.insert("Two".to_string(), 2.0);
10
11 assert_eq!("0".to_string(), "{Zero}".format(&vars)?);
12 assert_eq!("0.00".to_string(), "{Zero:.2}".format(&vars)?);
13 assert_eq!("3.33333".to_string(), "{Three:.5}".format(&vars)?);
14 assert_eq!("2".to_string(), "{Two}".format(&vars)?);
15 assert_eq!("0.00 ".to_string(), "{Zero:<5.2}".format(&vars)?);
16
17 Ok(())
18 }
19
20 #[test]
21 fn test_fmt_float32() -> Result<(), FmtError> {
22 let mut vars: HashMap<String, f32> = HashMap::new();
23 vars.insert("Zero".to_string(), 0.0);
24 vars.insert("Three".to_string(), 10.0 / 3.0);
25 vars.insert("Two".to_string(), 2.0);
26
27 assert_eq!("0".to_string(), "{Zero}".format(&vars)?);
28 assert_eq!("0.00".to_string(), "{Zero:.2}".format(&vars)?);
29 assert_eq!("3.33333".to_string(), "{Three:.5}".format(&vars)?);
30 assert_eq!("2".to_string(), "{Two}".format(&vars)?);
31 assert_eq!("0.00 ".to_string(), "{Zero:<5.2}".format(&vars)?);
32
33 Ok(())
34 }