Skip to content

Commit

Permalink
Set up to begin Spring 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
kbuffardi committed Apr 9, 2024
1 parent d31c700 commit e16b55e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
24 changes: 13 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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++ \
Expand All @@ -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
3 changes: 1 addition & 2 deletions Password.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions Password.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions PasswordTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

0 comments on commit e16b55e

Please sign in to comment.