diff options
-rw-r--r-- | 014literal_noninteger.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/014literal_noninteger.cc b/014literal_noninteger.cc index 11a3fc70..643ad587 100644 --- a/014literal_noninteger.cc +++ b/014literal_noninteger.cc @@ -20,7 +20,7 @@ if (is_noninteger(s)) { :(code) bool is_noninteger(const string& s) { return s.find_first_not_of("0123456789-.") == string::npos - && s.find('.') != string::npos; + && std::count(s.begin(), s.end(), '.') == 1; } double to_double(string n) { @@ -30,3 +30,10 @@ double to_double(string n) { assert(*end == '\0'); return result; } + +void test_is_noninteger() { + CHECK(!is_noninteger("1234")); + CHECK(!is_noninteger("1a2")); + CHECK(is_noninteger("234.0")); + CHECK(!is_noninteger("...")); +} |