diff --git a/Dockerfile b/Dockerfile index 2582535..89800f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,16 @@ -FROM ubuntu:22.04 -LABEL title="Unit Testing CPP" +FROM ubuntu:latest +LABEL title="CPP Container" LABEL version=0.1 ENV GTEST_REPO=/googletest ENV GTEST_DIR=${GTEST_REPO}/googletest ENV WORKDIR=/usr/src WORKDIR /usr/src -COPY . ${WORKDIR} + +# Set Docker arguments +ARG DEBIAN_FRONTEND=noninteractive # Install dependencies RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive \ apt-get install -y \ build-essential \ g++ \ @@ -18,14 +19,15 @@ RUN apt-get update && \ dos2unix # Setup GoogleTest -RUN git clone https://github.com/google/googletest ${GTEST_REPO} -RUN mkdir ${GTEST_REPO}/build -RUN cd ${GTEST_REPO}/build && cmake .. -DBUILD_GMOCK=OFF -RUN make -RUN cd ${WORKDIR} +RUN git clone --depth=1 https://github.com/google/googletest ${GTEST_REPO} +RUN mkdir ${GTEST_REPO}/build && cd ${GTEST_REPO}/build \ + && cmake .. -DBUILD_GMOCK=OFF && make && cd ${WORKDIR} + +# Copy repo source into container +COPY . ${WORKDIR} -# Assure Unix linefeed in shell command +# Assure Unix linefeed for all files RUN find . -type f -print0 | xargs -0 dos2unix -- -# Build and run tests +# Build project CMD sh -c ${WORKDIR}/test_runner.sh \ No newline at end of file diff --git a/Password.cpp b/Password.cpp index 3d3e174..bd06cce 100644 --- a/Password.cpp +++ b/Password.cpp @@ -12,10 +12,9 @@ using std::string; int Password::count_leading_characters(string phrase){ int repetition = 1; int index = 0; - while( index < phrase.length()-1 && phrase[index] == phrase[index+1] ){ repetition++; index++; } return repetition; -} \ No newline at end of file +} diff --git a/Password.h b/Password.h index 8f4ab34..5fa6591 100644 --- a/Password.h +++ b/Password.h @@ -9,11 +9,11 @@ class Password { public: /* - The function receives a string counts how many times the same character + The function receives a string and counts how many times the same character occurs at the beginning of the string, before any other characters (or the end of the string). The function is case-sensitive so 'Z' is different than 'z' and any ASCII characters are allowed. */ - int count_leading_characters(string); + int count_leading_characters(string word); }; #endif diff --git a/PasswordTest.cpp b/PasswordTest.cpp index d12cd54..a209833 100644 --- a/PasswordTest.cpp +++ b/PasswordTest.cpp @@ -14,13 +14,9 @@ class PracticeTest : public ::testing::Test virtual void TearDown(){} //clean up after each test, (before destructor) }; -TEST(PasswordTest, smoke_test) -{ - ASSERT_TRUE( 1 == 1 ); -} TEST(PasswordTest, single_letter_password) { Password my_password; int actual = my_password.count_leading_characters("Z"); - ASSERT_EQ(1,actual); + ASSERT_EQ(1, actual); } \ No newline at end of file diff --git a/README.md b/README.md index 70e36e7..8cbd95d 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ With Docker running, execute the following commands in order. This will generate the container image. It needs to be run each time the container configuration changes. -`docker build -t gtest .` +`docker build -t cpp-container .` This will use the current code, attempt to build it, and run its tests within the container. If you change the code (and not the container configuration), you only need to repeat this command. -`docker run -v "$(pwd)":/usr/src -it gtest` +`docker run -v "$(pwd)":/usr/src -it cpp-container`