about summary refs log tree commit diff
path: root/src/libcoretest/fmt/float.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-02-09 08:47:35 -0500
committerGitHub <noreply@github.com>2017-02-09 08:47:35 -0500
commit8f65d7543b12d7789bbf2b3cfa41a683553ec366 (patch)
treed399dcf8b9d51ad82ef644e0a575bb67ecfa1521 /src/libcoretest/fmt/float.rs
parente32e2d47d05848a20814adee44e1a47bf5b184fc (diff)
parent2ba0b65c27724b99f2624c4245698e8ef36a2cf2 (diff)
downloadrust-8f65d7543b12d7789bbf2b3cfa41a683553ec366.tar.gz
rust-8f65d7543b12d7789bbf2b3cfa41a683553ec366.zip
Rollup merge of #39615 - phungleson:corefloat, r=alexcrichton
Improve format float

* Move float into mod float like in test
* Add more tests for f64 f32, lower exp, upper exp, which can come if handy in the future if we want refactor further
* Use `assert_eq` for clearer error messages
Diffstat (limited to 'src/libcoretest/fmt/float.rs')
-rw-r--r--src/libcoretest/fmt/float.rs32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/libcoretest/fmt/float.rs b/src/libcoretest/fmt/float.rs
index 16cd2feddc0..695001312e4 100644
--- a/src/libcoretest/fmt/float.rs
+++ b/src/libcoretest/fmt/float.rs
@@ -9,11 +9,29 @@
 // except according to those terms.
 
 #[test]
-fn test_format_float() {
-    assert!("1" == format!("{:.0}", 1.0f64));
-    assert!("9" == format!("{:.0}", 9.4f64));
-    assert!("10" == format!("{:.0}", 9.9f64));
-    assert!("9.8" == format!("{:.1}", 9.849f64));
-    assert!("9.9" == format!("{:.1}", 9.851f64));
-    assert!("1" == format!("{:.0}", 0.5f64));
+fn test_format_f64() {
+    assert_eq!("1", format!("{:.0}", 1.0f64));
+    assert_eq!("9", format!("{:.0}", 9.4f64));
+    assert_eq!("10", format!("{:.0}", 9.9f64));
+    assert_eq!("9.8", format!("{:.1}", 9.849f64));
+    assert_eq!("9.9", format!("{:.1}", 9.851f64));
+    assert_eq!("1", format!("{:.0}", 0.5f64));
+    assert_eq!("1.23456789e6", format!("{:e}", 1234567.89f64));
+    assert_eq!("1.23456789e3", format!("{:e}", 1234.56789f64));
+    assert_eq!("1.23456789E6", format!("{:E}", 1234567.89f64));
+    assert_eq!("1.23456789E3", format!("{:E}", 1234.56789f64));
+}
+
+#[test]
+fn test_format_f32() {
+    assert_eq!("1", format!("{:.0}", 1.0f32));
+    assert_eq!("9", format!("{:.0}", 9.4f32));
+    assert_eq!("10", format!("{:.0}", 9.9f32));
+    assert_eq!("9.8", format!("{:.1}", 9.849f32));
+    assert_eq!("9.9", format!("{:.1}", 9.851f32));
+    assert_eq!("1", format!("{:.0}", 0.5f32));
+    assert_eq!("1.2345679e6", format!("{:e}", 1234567.89f32));
+    assert_eq!("1.2345679e3", format!("{:e}", 1234.56789f32));
+    assert_eq!("1.2345679E6", format!("{:E}", 1234567.89f32));
+    assert_eq!("1.2345679E3", format!("{:E}", 1234.56789f32));
 }