0% found this document useful (0 votes)
39 views6 pages

Project 0

This document provides instructions for Assignment 0, which involves testing a pre-implemented TweetMgr class. Students are given the TweetMgr class interface in TweetMgr.h, compiled implementation code in TweetMgr.cpp.obj, and an initial test file TweetMgrTest.cpp to add test code to. The goal is to thoroughly test all the methods of TweetMgr described in TweetMgr.h, including adding, retrieving, deleting tweets and checking for tweets by timestamp or sender. Guidelines are provided on writing clean automated test code, handling exceptions, and ensuring the tests will work consistently.

Uploaded by

sdfkdnbvbr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views6 pages

Project 0

This document provides instructions for Assignment 0, which involves testing a pre-implemented TweetMgr class. Students are given the TweetMgr class interface in TweetMgr.h, compiled implementation code in TweetMgr.cpp.obj, and an initial test file TweetMgrTest.cpp to add test code to. The goal is to thoroughly test all the methods of TweetMgr described in TweetMgr.h, including adding, retrieving, deleting tweets and checking for tweets by timestamp or sender. Guidelines are provided on writing clean automated test code, handling exceptions, and ensuring the tests will work consistently.

Uploaded by

sdfkdnbvbr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CS2201

Fall 2022
Assignment No. 0

Reminder: The Academic Honesty Policy posted on Brightspace is applicable to all work you do this semester in
CS2201.

Purpose: This assignment has several goals:


1. This is a relatively simple assignment, meant to get you back into programming after the semester break.
2. Make sure you can edit/compile/run C++ code in whatever IDE you will be using this semester (preferably CLion).
3. Gain experience in using and manipulating objects in C++.
4. Gain experience in writing test code that will thoroughly test a C++ class.
5. Make sure you can correctly submit code for grading via Brightspace.
You will be provided a C++ class that represents some type of object and you will write a program that exercises that
class as fully as possible. Note: your task is only to test the supplied class; not to implement the class.

Assignment: This assignment deals with a program which stores a collection of tweets. The tweets will be stored in
sorted (chronological) order which is based on timestamps. The TweetMgr class is able to contain up to MAX_TWEETS
(currently defined to be 50) tweets. The TweetMgr.h file provides a detailed description of all the functions provided by
the class – you will want to read this file carefully.

You will be provided with the source code that supports the tweets and object code (pre-compiled code) that supports the
TweetMgr. Your task will be to test the provided TweetMgr class as fully as possible to ensure it works as expected. This
is known as test-driven development: we write code to test that a class works as expected, and afterward we write the
class such that it passes all tests (the only difference is that I am giving you working code so that you can see if your tests
are correct or not). Note: your task is to only test the TweetMgr class, not to implement the TweetMgr class. All the
functions that you are to test are fully described in the TweetMgr.h file.

Functional Specifications: You will be supplied five files:

• Tweet.h: declaration of the Tweet class (do not change)


• Tweet.cpp: definition of the Tweet class (do not change)
• TweetMgr.h: declaration of the TweetMgr class (do not change)
• TweetMgr.cpp.obj or TweetMgr.cpp.o: compiled object code of the TweetMgr class which implements all the
class methods [it was produced from a properly working TweetMgr.cpp file] Note that this is a file containing
binary information – if you attempt to look at it in the editor it will be gibberish. (do not change)
• TweetMgrTest.cpp: initial test program. Your job is to add code to the TweetMgrTest.cpp file to fully
test/exercise the TweetMgr class.

The TweetMgr.h file contains a detailed description, known as the class declaration, of a set of functions to manipulate a
collection of Tweet objects. A predetermined maximum size of the collection is defined by the constant identifier
MAX_TWEETS. You will also be supplied a compiled object file, TweetMgr.cpp.obj or TweetMgr.cpp.o, which
implements all the functions [it was created from a properly working TweetMgr.cpp file]. You will also be provided
with an initial test program: TweetMgrTest.cpp. Your job is to add code to the TweetMgrTest.cpp file to fully
test/exercise the TweetMgr class. Note: your task is to only test the TweetMgr class, not to implement the TweetMgr
class. You are not to test the Tweet class – you can assume it works as given (if you think you have found a bug in the
Tweet class, please report them to the instructor or post them on Piazza). Please ignore any messages from CLion that the
methods are not implemented.
Here are the methods/features of the TweetMgr class that you are to test (see the TweetMgr.h file for descriptions that are
more complete):

TweetMgr class
Methods Function
TweetMgr() Default constructor – creates an empty TweetMgr
getNumTweets() Return the total number of Tweets in the TweetMgr
insert(const Tweet &t) Add/insert a tweet to the TweetMgr
retrieve(size_t index) Returns the tweet at the specified index
exists(size_t ts) Returns true if a tweet exists at the given timestamp
count(const string& sender) Returns the number of tweets from a specified sender
getTweets() Return a string of all tweets
getTweets(const string& sender) Return a string of all tweets sent by a specified sender
getTweets(size_t ts) Return a string of all tweets at a given timestamp
getTweets(size_t ts1, size_t ts2) Return a string of all tweets in a range of two given timestamps
deleteTweets() Deletes all tweets
deleteTweets(const string& sender) Delete all tweets from the specified sender
deleteTweets(size_t ts) Deletes the tweets whose timestamps are earlier than the
parameter timestamp
deleteTweets(size_t ts1, size_t ts2) Deletes all tweets between a range of two timestamps

Implementation details: Here are a few notes that might be helpful:


1. You are to download a zip file which is provided with this specification – be sure to download the correct one for
your platform. The zip file contains a CLion project that includes starter code for this project. You must
unzip/extract the files before you work on them. Once you unzip the file, you can open the project by starting
CLion, then specify that you want to “Open Project”, and then navigate to the folder you just extracted. Be sure
to Open the project, and not Import it. When you open the project, let CLion do its initialization work and load
symbols (there are more details later in this document). The code as provided compiles cleanly (no errors or
warnings) and executes successfully – though it only performs minimal testing in its distributed form. Again, you
must extract the files before you work on them. There are more details including pictures at the end of this
document.
2. The test code that you write should be fully automated, as demonstrated in the small segment of provided test
code. That means your test code should not depend upon reading any input from a user nor should it require the
user to visually inspect any output. Relying on the user to enter any special cases to be tested is prone to
omissions. Plus, anyone else who uses such test code would not know what data to enter so that the class is fully
tested.
3. The test code that you write should work correctly regardless of when the code is run – it should continue to run
correctly a year from now. That means you should not generate timestamps based on today’s date, as today’s date
changes depending upon when the test is run. You should also not generate random timestamps unless the order
of the tweets you create does not matter (typically not true).
4. You will likely be performing some operations with C++ strings. C++ string operations are described here. You
will only need a few of the available operations in this assignment, such as length, at (or use [ ]), assignment,
equality operator or compare method, substr, and maybe others.
5. You will need to test the Boolean return value of the exists() function. C++ defines two literal constants
true and false – please note that they are all lowercase. Please remember to use Boolean-zen while writing
your code.
6. The length() method of the string class returns a value of type size_t (an unsigned integer type). We also use
variables and parameters of type size_t whenever we expect the value to be non-negative (e.g., parameters that
represent an array index are declared to be size_t variables). The compiler may give you conversion warning
messages if you attempt to assign/compare these values to a value of type int. Your homework submissions are
expected to have clean compiles (no errors or warnings). To eliminate this particular warning, you can cast the
size_t values to an int, or cast the int values to type size_t if you know the integer values are not negative. Note:
all grading will be done with CLion and the clang compiler, which may produce different warning & error
messages than other compilers – if you are developing with something other than CLion/clang, it is your
responsibility to ensure you code compiles cleanly with CLion/clang.
7. The TweetMgr.h specifies that some methods throw an exception if someone attempts to perform an operation
that is not allowed (e.g., adding a tweet to a full TweetMgr). When an exception is thrown it will cause your
program to stop executing if the exception is not handled. You will want to test the class to make sure exceptions
are thrown appropriately, so you need to know how to handle the exceptions. To handle exceptions you use what
is known as try-catch blocks, which can catch the thrown exceptions. The distributed TweetMgrTest.cpp file
contains a try-catch block that you can duplicate to test the exception throwing capabilities of the TweetMgr class.
Your test program must use try-catch blocks whenever it expects an exception to be thrown – this will allow your
program to continue executing. You should write a new try-catch block for each exception you are testing. More
information on C++ exceptions can be found in chapter 21 of our text (zyBooks).
8. Note that if you do not understand how a method of the TweetMgr class is supposed to act from its
description/specification, then you can simply try it out – you were supplied a working class as a part of the
assignment.
9. Every semester we have issues with students who submit code that fails to compile with the grading script even
though the code compiles on their machine. If you correctly open (not import) the provided CLion project, this
should not be an issue. But just to make sure, please check your CMakeLists.txt file and ensure that it specifies
these flags for your C++ compiler: -Wall -Werror -Wextra -pedantic -pedantic-errors
10. To be perfectly clear, your job in this assignment is to fully test the TweetMgr class to the best of your ability.
Your job is not to write the TweetMgr class – that code has been provided to you in the form of a compiled object
file. There is a secondary document provided with the project that discusses testing and how to configure your test
code – it is optional but contains some useful information.

Background: A TweetMgr simply manages a collection of tweets. A tweet is simply an object containing three items: a
sender, the text of the tweet, and a timestamp of when it was sent. Tweets are created/supported through the Tweet class.
Again, you may assume the Tweet class is bug-free. The purpose of this assignment is to only test the TweetMgr class.

The properties of the Tweet class (which is already provided to you) is given below:

Tweet class
Methods Function
Tweet() Default constructor – creates a Tweet object having an empty sender
and text, and timestamp of zero
Tweet(size_t ts, const string& Overloaded constructor that creates a Tweet object with the provided
sender, const string& msg) timestamp, sender, and message
string getUser() Return the sender of the tweet
void setUser(const string& newUser) Changes the sender of the tweet
string getText() Return the message of the tweet
void setText(const string& newText) Changes the message of the tweet
size_t getTimestamp() Return the timestamp of the tweet
void setTimestamp(size_t newTime) Changes the timestamp of the tweet
string toString() Return a formatted string version of the tweet, containing the sender,
the message, and the timestamp
bool equals(const Tweet& rhs) Compares two tweets for equality, comparing the senders, the
messages, and the timestamps
bool operator==(const Tweet& rhs) Equality and relational operators that compares two tweets by
bool operator!=(const Tweet& rhs) comparing only their timestamps. Useful for sorting tweets.
bool operator<(const Tweet& rhs)
bool operator<=(const Tweet& rhs)
bool operator>(const Tweet& rhs)
bool operator>=(const Tweet& rhs)
bool operator==(size_t ts) Overloaded equality and relational operators that compares a tweet
bool operator!=(size_t ts) against a timestamp value. The tweet must be on the left-hand side
bool operator<(size_t ts) of the operator for these to work.
bool operator<=(size_t ts)
bool operator>(size_t ts)
bool operator>=(size_t ts)
Note on using defined operators: In the above class description you see that several operators have been defined for the
class; for example “operator==” has been defined. You can use these like any other method of the class; for example if
t1 & t2 were two Tweet objects, you could type: t1.operator==(t2) to test if the two tweets had the same
timestamp. However, it is much easier to simply use them as the operators you know and love; for example: t1==t2.
Typing t1==t2 calls the operator== method.

Many of the methods of the Tweet class are declared to be const methods; indicating that they do not modify the object on
which they are called (the const declaration is not shown above to save space). The Tweet class has overloaded the
insertion operator so that tweet objects can easily be displayed with the << insertion operator.

You are NOT allowed to make any changes to the Tweet class.

Submission for grading: When you have completed your work on this assignment, please submit your
TweetMgrTest.cpp file for grading, as that is the only file you should have changed while working on this assignment.
Submit ONLY the single source file – please do not submit a zip file containing your entire project, and do not submit the
other TweetMgr/Tweet files. You can submit the files by visiting the assignment page in Brightspace (click on the
assignment name), scroll down to the “Submit Files” section, and add the file by clicking on the “Add a file” button and
finding the file to attach.

After submitting your homework, it is good practice to verify your submission. Revisit the assignment page in
Brightspace and make sure that your file was successfully submitted. Then click on the file to open it up so that you can
verify that you submitted the correct file, as opposed to some older version of the file. It is your responsibility to ensure
the correctness of your submission – this is true for all assignments.

Grading: This project is worth 25 points (half of a normal assignment). Your grade on this project will be based on the
thoroughness of your testing of the TweetMgr class performed by your TweetMgrTest.cpp file. Please make sure that your
code compiles without errors or warnings, and it runs to completion without prematurely terminating (say, due to an
uncaught exception).

You should also review the syllabus regarding the penalties for late programming assignments.

Note that we never grade test code for good programming style. However, it is to your benefit to use good style. We will
be using this test program for several assignments, and you will need to update it to test new/different behaviors. Such
updates are much easier when the test program is written with good style, using separate functions to test different
methods of the class. Past students have complained that updating the program was very hard for them since their code
was such a mess (which they thought did not matter since the code was not graded on style).

[There is more information below on opening provided projects in CLion.]


=============================================================================
Opening a CLion project:

1. Unzip the provided zip file; use the one appropriate for your platform. This will create a folder named
project0-Windows or project0-MacOS-Intel or project0-MacOS-M1 that contains a set of
files.
2. Start up CLion. If it brings up an existing project, close that project down by selecting “Close Project” from
the File drop-down menu. This will return you to the CLion welcome screen:

3. From the CLion welcome screen, select “Open”.


4. Navigate to the project0-Windows or project0-MacOS-Intel or project0-MacOS-M1 folder
that you unzipped in step 1. The folder should be displayed slightly differently than other folders. Select the
folder and press OK.
5. At this point, CLion will open up and display to you the TweetMgrTest.cpp file. At the bottom of the screen
you will see status messages as it loads necessary symbols, etc. Do not do anything until the status
messages stop. When the status messages stop, it should look something like this:
6. You now should be able to build the project and then run it (remember that you should always do those two
steps separately).

You might also like