Skip to content

Commit e16b55e

Browse files
committed
Set up to begin Spring 2024
1 parent d31c700 commit e16b55e

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

Dockerfile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
FROM ubuntu:22.04
2-
LABEL title="Unit Testing CPP"
1+
FROM ubuntu:latest
2+
LABEL title="CPP Container"
33
LABEL version=0.1
44
ENV GTEST_REPO=/googletest
55
ENV GTEST_DIR=${GTEST_REPO}/googletest
66
ENV WORKDIR=/usr/src
77
WORKDIR /usr/src
8-
COPY . ${WORKDIR}
8+
9+
# Set Docker arguments
10+
ARG DEBIAN_FRONTEND=noninteractive
911

1012
# Install dependencies
1113
RUN apt-get update && \
12-
DEBIAN_FRONTEND=noninteractive \
1314
apt-get install -y \
1415
build-essential \
1516
g++ \
@@ -18,14 +19,15 @@ RUN apt-get update && \
1819
dos2unix
1920

2021
# Setup GoogleTest
21-
RUN git clone https://github.com/google/googletest ${GTEST_REPO}
22-
RUN mkdir ${GTEST_REPO}/build
23-
RUN cd ${GTEST_REPO}/build && cmake .. -DBUILD_GMOCK=OFF
24-
RUN make
25-
RUN cd ${WORKDIR}
22+
RUN git clone --depth=1 https://github.com/google/googletest ${GTEST_REPO}
23+
RUN mkdir ${GTEST_REPO}/build && cd ${GTEST_REPO}/build \
24+
&& cmake .. -DBUILD_GMOCK=OFF && make && cd ${WORKDIR}
25+
26+
# Copy repo source into container
27+
COPY . ${WORKDIR}
2628

27-
# Assure Unix linefeed in shell command
29+
# Assure Unix linefeed for all files
2830
RUN find . -type f -print0 | xargs -0 dos2unix --
2931

30-
# Build and run tests
32+
# Build project
3133
CMD sh -c ${WORKDIR}/test_runner.sh

Password.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ using std::string;
1212
int Password::count_leading_characters(string phrase){
1313
int repetition = 1;
1414
int index = 0;
15-
1615
while( index < phrase.length()-1 && phrase[index] == phrase[index+1] ){
1716
repetition++;
1817
index++;
1918
}
2019
return repetition;
21-
}
20+
}

Password.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class Password
99
{
1010
public:
1111
/*
12-
The function receives a string counts how many times the same character
12+
The function receives a string and counts how many times the same character
1313
occurs at the beginning of the string, before any other characters (or the
1414
end of the string). The function is case-sensitive so 'Z' is different than
1515
'z' and any ASCII characters are allowed.
1616
*/
17-
int count_leading_characters(string);
17+
int count_leading_characters(string word);
1818
};
1919
#endif

PasswordTest.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ class PracticeTest : public ::testing::Test
1414
virtual void TearDown(){} //clean up after each test, (before destructor)
1515
};
1616

17-
TEST(PasswordTest, smoke_test)
18-
{
19-
ASSERT_TRUE( 1 == 1 );
20-
}
2117
TEST(PasswordTest, single_letter_password)
2218
{
2319
Password my_password;
2420
int actual = my_password.count_leading_characters("Z");
25-
ASSERT_EQ(1,actual);
21+
ASSERT_EQ(1, actual);
2622
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ With Docker running, execute the following commands in order.
1111
This will generate the container image. It needs to be run each time the
1212
container configuration changes.
1313

14-
`docker build -t gtest .`
14+
`docker build -t cpp-container .`
1515

1616
This will use the current code, attempt to build it, and run its tests
1717
within the container. If you change the code (and not the container
1818
configuration), you only need to repeat this command.
1919

20-
`docker run -v "$(pwd)":/usr/src -it gtest`
20+
`docker run -v "$(pwd)":/usr/src -it cpp-container`

0 commit comments

Comments
 (0)