about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-10 11:15:28 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-10 11:15:28 -0700
commit37537bf347a27392433a61e44ed8ad416e8cbecd (patch)
treee7b9ce08e5eec95fa7cdd68fcabc3432e45d1d12
parente709c65e67f873541b958ba43e425b08f3e073e3 (diff)
downloadmu-37537bf347a27392433a61e44ed8ad416e8cbecd.tar.gz
1965 - don't die on '-' ingredient
Thanks Caleb Couch.
-rw-r--r--002test.cc14
1 files changed, 13 insertions, 1 deletions
diff --git a/002test.cc b/002test.cc
index d59309a2..37698d30 100644
--- a/002test.cc
+++ b/002test.cc
@@ -82,7 +82,9 @@ void run_test(size_t i) {
 }
 
 bool is_integer(const string& s) {
-  return s.find_first_not_of("0123456789-") == string::npos;
+  return s.find_first_not_of("0123456789-") == string::npos
+      && s.find('-', 1) == string::npos
+      && s.find_first_of("0123456789") != string::npos;
 }
 
 long long int to_integer(string n) {
@@ -94,5 +96,15 @@ long long int to_integer(string n) {
   return result;
 }
 
+void test_is_integer() {
+  CHECK(is_integer("1234"));
+  CHECK(is_integer("-1"));
+  CHECK(!is_integer("234.0"));
+  CHECK(is_integer("-567"));
+  CHECK(!is_integer("89-0"));
+  CHECK(!is_integer("-"));
+  CHECK(!is_integer("1e3"));  // not supported
+}
+
 :(before "End Includes")
 #include<cstdlib>