about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-06 18:44:48 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-06 18:44:48 -0700
commitdd3bd1224505413bb91a3f99a95a3936e1347f21 (patch)
tree1b4ffa4de8dea6c1113f721b9c4ad2c47af3faa8
parent41f5188dcf0da06e49bb9cbdb50f134d4a1b83bc (diff)
downloadmu-dd3bd1224505413bb91a3f99a95a3936e1347f21.tar.gz
2255 - bug in detecting non-integers
Thanks Caleb Couch.
-rw-r--r--014literal_noninteger.cc9
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("..."));
+}