mirror of
https://github.com/serde-rs/json.git
synced 2025-10-02 07:21:29 +00:00
Fix f64 tests
This commit is contained in:
parent
507d3d69ff
commit
898b2a56b2
@ -41,7 +41,7 @@ fn main() {
|
||||
map.insert("y".to_string(), 2.0);
|
||||
|
||||
let s = serde_json::to_string(&map).unwrap();
|
||||
assert_eq!(s, "{\"x\":1,\"y\":2}");
|
||||
assert_eq!(s, "{\"x\":1.0,\"y\":2.0}");
|
||||
|
||||
let deserialized_map: Map<String, f64> = serde_json::from_str(&s).unwrap();
|
||||
assert_eq!(map, deserialized_map);
|
||||
@ -78,7 +78,7 @@ fn main() {
|
||||
let point = Point { x: 1.0, y: 2.0 };
|
||||
|
||||
let s = serde_json::to_string(&point).unwrap();
|
||||
assert_eq!(s, "{\"x\":1,\"y\":2}");
|
||||
assert_eq!(s, "{\"x\":1.0,\"y\":2.0}");
|
||||
|
||||
let deserialized_point: Point = serde_json::from_str(&s).unwrap();
|
||||
assert_eq!(point, deserialized_point);
|
||||
|
@ -117,18 +117,14 @@ fn test_write_i64() {
|
||||
|
||||
#[test]
|
||||
fn test_write_f64() {
|
||||
let min_string = format!("{:?}", f64::MIN);
|
||||
let max_string = format!("{:?}", f64::MAX);
|
||||
let epsilon_string = format!("{:?}", f64::EPSILON);
|
||||
|
||||
let tests = &[
|
||||
(3.0, "3"),
|
||||
(3.0, "3.0"),
|
||||
(3.1, "3.1"),
|
||||
(-1.5, "-1.5"),
|
||||
(0.5, "0.5"),
|
||||
(f64::MIN, &min_string),
|
||||
(f64::MAX, &max_string),
|
||||
(f64::EPSILON, &epsilon_string),
|
||||
(f64::MIN, "-1.7976931348623157e308"),
|
||||
(f64::MAX, "1.7976931348623157e308"),
|
||||
(f64::EPSILON, "2.220446049250313e-16"),
|
||||
];
|
||||
test_encode_ok(tests);
|
||||
test_pretty_encode_ok(tests);
|
||||
|
Loading…
x
Reference in New Issue
Block a user