Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: base/strings/string_number_conversions_unittest.cc

Issue 2415353002: Add boundary test case to StringToDouble (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/string_number_conversions.h" 5 #include "base/strings/string_number_conversions.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <limits.h> 8 #include <limits.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 738
739 // Test different forms of representation. 739 // Test different forms of representation.
740 {"2.99792458e8", 299792458.0, true}, 740 {"2.99792458e8", 299792458.0, true},
741 {"149597870.691E+3", 149597870691.0, true}, 741 {"149597870.691E+3", 149597870691.0, true},
742 {"6.", 6.0, true}, 742 {"6.", 6.0, true},
743 743
744 // Test around the largest/smallest value that a double can represent. 744 // Test around the largest/smallest value that a double can represent.
745 {"9e307", 9e307, true}, 745 {"9e307", 9e307, true},
746 {"1.7976e308", 1.7976e308, true}, 746 {"1.7976e308", 1.7976e308, true},
747 {"1.7977e308", HUGE_VAL, false}, 747 {"1.7977e308", HUGE_VAL, false},
748 {"1.797693134862315807e+308", HUGE_VAL, true},
749 {"1.797693134862315808e+308", HUGE_VAL, false},
748 {"9e308", HUGE_VAL, false}, 750 {"9e308", HUGE_VAL, false},
749 {"9e309", HUGE_VAL, false}, 751 {"9e309", HUGE_VAL, false},
750 {"9e999", HUGE_VAL, false}, 752 {"9e999", HUGE_VAL, false},
751 {"9e1999", HUGE_VAL, false}, 753 {"9e1999", HUGE_VAL, false},
752 {"9e19999", HUGE_VAL, false}, 754 {"9e19999", HUGE_VAL, false},
753 {"9e99999999999999999999", HUGE_VAL, false}, 755 {"9e99999999999999999999", HUGE_VAL, false},
754 {"-9e307", -9e307, true}, 756 {"-9e307", -9e307, true},
755 {"-1.7976e308", -1.7976e308, true}, 757 {"-1.7976e308", -1.7976e308, true},
756 {"-1.7977e308", -HUGE_VAL, false}, 758 {"-1.7977e308", -HUGE_VAL, false},
759 {"-1.797693134862315807e+308", -HUGE_VAL, true},
760 {"-1.797693134862315808e+308", -HUGE_VAL, false},
757 {"-9e308", -HUGE_VAL, false}, 761 {"-9e308", -HUGE_VAL, false},
758 {"-9e309", -HUGE_VAL, false}, 762 {"-9e309", -HUGE_VAL, false},
759 {"-9e999", -HUGE_VAL, false}, 763 {"-9e999", -HUGE_VAL, false},
760 {"-9e1999", -HUGE_VAL, false}, 764 {"-9e1999", -HUGE_VAL, false},
761 {"-9e19999", -HUGE_VAL, false}, 765 {"-9e19999", -HUGE_VAL, false},
762 {"-9e99999999999999999999", -HUGE_VAL, false}, 766 {"-9e99999999999999999999", -HUGE_VAL, false},
763 767
764 // Test more exponents. 768 // Test more exponents.
765 {"1e-2", 0.01, true}, 769 {"1e-2", 0.01, true},
766 {"42 ", 42.0, false}, 770 {"42 ", 42.0, false},
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 }; 892 };
889 893
890 for (const auto& test : cases) { 894 for (const auto& test : cases) {
891 double output; 895 double output;
892 EXPECT_TRUE(StringToDouble(test.input, &output)); 896 EXPECT_TRUE(StringToDouble(test.input, &output));
893 EXPECT_EQ(bit_cast<uint64_t>(output), test.expected); 897 EXPECT_EQ(bit_cast<uint64_t>(output), test.expected);
894 } 898 }
895 } 899 }
896 900
897 } // namespace base 901 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698