1 extern crate dtoa;
2
3 use std::str;
4
5 #[test]
test_f64()6 fn test_f64() {
7 test_write(1.234e20f64, "123400000000000000000.0");
8 test_write(1.234e21f64, "1.234e21");
9 test_write(2.71828f64, "2.71828");
10 test_write(0.0f64, "0.0");
11 test_write(-0.0f64, "-0.0");
12 test_write(1.1e128f64, "1.1e128");
13 test_write(1.1e-64f64, "1.1e-64");
14 test_write(2.718281828459045f64, "2.718281828459045");
15 test_write(5e-324f64, "5e-324");
16 test_write(::std::f64::MAX, "1.7976931348623157e308");
17 }
18
19 #[test]
test_f32()20 fn test_f32() {
21 test_write(1.234e20f32, "123400000000000000000.0");
22 test_write(1.234e21f32, "1.234e21");
23 test_write(2.71828f32, "2.71828");
24 test_write(0.0f32, "0.0");
25 test_write(-0.0f32, "-0.0");
26 test_write(1.1e32f32, "1.1e32");
27 test_write(1.1e-32f32, "1.1e-32");
28 test_write(2.7182817f32, "2.7182817");
29 test_write(1e-45f32, "1e-45");
30 test_write(::std::f32::MAX, "3.4028235e38");
31 }
32
test_write<F: dtoa::Floating>(value: F, expected: &'static str)33 fn test_write<F: dtoa::Floating>(value: F, expected: &'static str) {
34 let mut buf = [b'\0'; 30];
35 let len = dtoa::write(&mut buf[..], value).unwrap();
36 let result = str::from_utf8(&buf[..len]).unwrap();
37 assert_eq!(result, expected.to_string());
38 }
39