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-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 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/main.cpp b/main.cpp index a8c04a8..4afd3ec 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 0; +} \ 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..e72e678 --- /dev/null +++ b/test.cpp @@ -0,0 +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-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(); +} \ No newline at end of file