Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
c-echo-count
test

CMakeCache.txt
CMakeFiles/
cmake_install.cmake
Makefile
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 3 additions & 2 deletions c-count.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>

// count function should go here

int count(const std::string& phrase) {
return 0;
}
12 changes: 12 additions & 0 deletions c-echo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>

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;
}
11 changes: 8 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#include <iostream>
#include <string>

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;
}
5 changes: 5 additions & 0 deletions main2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "c-echo.h"

int main(int argv, char** argc) {
std::cout << echo(argv, argc) << std::endl;
}
34 changes: 34 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
@@ -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();
}