From 1772b7902e06b88b4d2d76450e8f5f43cd3a3ce7 Mon Sep 17 00:00:00 2001 From: aishanianandd Date: Sun, 3 Aug 2025 16:09:11 -0700 Subject: [PATCH 1/5] Add user input --- main.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index a8c04a8..5802c70 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,12 @@ #include +#include int main() { - std::cout << "hello git" << std::endl; - return 1; -} + std::string name; + std::cout << "What is your name?" << std::endl; + std::cin >> name; + std::cout << "Hello " << name << "!" << std::endl; + + return 1; +} \ No newline at end of file From 8e70b8c3f8239b8436e0b2727ed04f075d251e08 Mon Sep 17 00:00:00 2001 From: aishanianandd Date: Sun, 3 Aug 2025 16:38:35 -0700 Subject: [PATCH 2/5] Fix main to return 0 not 1 --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index a8c04a8..f702143 100644 --- a/main.cpp +++ b/main.cpp @@ -3,5 +3,5 @@ int main() { std::cout << "hello git" << std::endl; - return 1; + return 0; } From 062199a26bf9997732006aa7695cb7e8ebeb85b0 Mon Sep 17 00:00:00 2001 From: aishanianandd Date: Sun, 3 Aug 2025 23:36:06 -0700 Subject: [PATCH 3/5] Add count function and update supporting files --- .gitignore | 7 +++++++ CMakeLists.txt | 18 ++++++++++++++++++ c-echo.h | 12 ++++++++++++ main2.cpp | 5 +++++ test.cpp | 13 +++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 c-echo.h create mode 100644 main2.cpp create mode 100644 test.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5aa8d9b --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +c-echo-count +test + +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +Makefile \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d3781e8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 3.0) + +ADD_SUBDIRECTORY(googletest) + +ADD_EXECUTABLE(c-echo + main2.cpp +) + +ADD_EXECUTABLE(c-echo-count + main.cpp +) + +ADD_EXECUTABLE(test + test.cpp +) + +TARGET_LINK_LIBRARIES(test gtest) +TARGET_COMPILE_DEFINITIONS(test PRIVATE gtest_disable_pthreads=ON) \ No newline at end of file diff --git a/c-echo.h b/c-echo.h new file mode 100644 index 0000000..6350044 --- /dev/null +++ b/c-echo.h @@ -0,0 +1,12 @@ +#include + +std::string echo(int length, char** chars) { + std::string ret = ""; + for(int i = 1; i < length; i++) { + ret += chars[i]; + if(i < length - 1) { + ret += " "; + } + } + return ret; +} \ No newline at end of file diff --git a/main2.cpp b/main2.cpp new file mode 100644 index 0000000..9756480 --- /dev/null +++ b/main2.cpp @@ -0,0 +1,5 @@ +#include "c-echo.h" + +int main(int argv, char** argc) { + std::cout << echo(argv, argc) << std::endl; +} \ No newline at end of file diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..3555352 --- /dev/null +++ b/test.cpp @@ -0,0 +1,13 @@ +#include "c-echo.h" + +#include "gtest/gtest.h" + +TEST(EchoTest, HelloWorld) { + char* test_val[3]; test_val[0] = "./c-echo"; test_val[1] = "hello"; test_val[2] = "world"; + EXPECT_EQ("hello world", echo(3,test_val)); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file From 264dcf757532daba14054304db63ba9b15f59254 Mon Sep 17 00:00:00 2001 From: aishanianandd Date: Sun, 3 Aug 2025 23:50:15 -0700 Subject: [PATCH 4/5] Add dummy count function for testing --- c-count.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/c-count.h b/c-count.h index 64f39a8..a46b180 100644 --- a/c-count.h +++ b/c-count.h @@ -1,4 +1,5 @@ #include -// count function should go here - +int count(const std::string& phrase) { + return 0; +} \ No newline at end of file From 8a8f0b5f7438320c4aa3f917deb3239e78befaf7 Mon Sep 17 00:00:00 2001 From: aishanianandd Date: Mon, 4 Aug 2025 00:00:57 -0700 Subject: [PATCH 5/5] Fixes #25 --- test.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/test.cpp b/test.cpp index 3555352..e72e678 100644 --- a/test.cpp +++ b/test.cpp @@ -1,13 +1,34 @@ #include "c-echo.h" +#include "c-count.h" #include "gtest/gtest.h" TEST(EchoTest, HelloWorld) { - char* test_val[3]; test_val[0] = "./c-echo"; test_val[1] = "hello"; test_val[2] = "world"; + char* test_val[3]; test_val[0] = "./c-echo-count"; test_val[1] = "hello"; test_val[2] = "world"; EXPECT_EQ("hello world", echo(3,test_val)); } +TEST(EchoTest, EmptyString) { + char* test_val[1]; test_val[0] = "./c-echo-count"; + EXPECT_EQ("", echo(1, test_val)); +} + +TEST(CountTest, HelloWorld) { + std::string test_str = "hello world"; + EXPECT_EQ(2, count(test_str)); +} + +TEST(CountTest, EmptyString) { + std::string test_str = ""; + EXPECT_EQ(0, count(test_str)); +} + +TEST(CountTest, ManySpaces) { + std::string test_str = " this string has weird spacing"; + EXPECT_EQ(5, count(test_str)); +} + int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } \ No newline at end of file