about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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>