Recent Changes - Search:
ECG Home

GitHub

People

Publications

Calendar

Projects

Fall 2017

Older Courses

Spring 2017

Fall 2016

Spring 2016

Fall 2015

Spring 2015

Fall 2014

Spring 2014

Fall 2013

Spring 2013

Fall 2012

Spring 2012

Fall 2011

Spring 2011

Fall 2010

Spring 2010

Fall 2009

Spring 2009

Fall 2008

Spring 2008

Fall 2007

HOWTOs

edit SideBar

PS5a

Home Assignments Lecture Blog Resources Discussion Group

Guitar Hero: RingBuffer implementation with unit tests and exceptions (Part A)

In Part A, we implement the ring buffer that will hold the guitar string position data, and write test functions and exception handling.

See http://www.cs.princeton.edu/courses/archive/spr15/cos126/assignments/guitar.html for the full assignment

Implementation

Write a class named RingBuffer that implements the following API:

public class RingBuffer
-------------------------------------------------------------------------------------------
        RingBuffer(int capacity)  // create an empty ring buffer, with given max capacity
int     size()                    // return number of items currently in the buffer
bool    isEmpty()                 // is the buffer empty (size equals zero)?
bool    isFull()                  // is the buffer full  (size equals capacity)?
void    enqueue(int16_t x)        // add item x to the end
int16_t dequeue()                 // delete and return item from the front
int16_t peek()                    // return (but do not delete) item from the front
-------------------------------------------------------------------------------------------

Your code must #include <stdint.h> header that defines the standard 16-bit integer type int16_t.

Important notes:

  1. The code should be in a pair of files named RingBuffer.cpp and RingBuffer.hpp.
  2. Attempts to instantiate with a capacity less than 1 should result in a std::invalid_argument exception, and the error message RB constructor: capacity must be greater than zero.
  3. Attempts to enqueue to a full buffer should result in a std::runtime_error exception, and the error message enqueue: can't enqueue to a full ring.
  4. Attempts to dequeue or peek from an empty buffer should result in a std::runtime_error exception, and an appropriate error message.

Debugging and testing

  • You should write a test.cpp file that uses the Boost functions BOOST_REQUIRE_THROW and BOOST_REQUIRE_NO_THROW to verify that your code properly throws the specified exceptions when appropriate (and does not throw an exception when it shouldn't). As usual, use BOOST_REQUIRE to exercise all methods of the class.
  • Your test file must exercise all methods of your ring buffer, and must exercise all exceptions.
  • You can write a main.cpp file that drives around your RingBuffer class, and use that for additional testing.
  • See the Attach:ps5a-test.cpp file that we went over in class to get started.

cpplint

Google's style guide is here: http://google-styleguide.googlecode.com/svn/trunk/cppguide.html

The cpplint.py file can be retrieved from http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py

Save the cpplint.py file on your machine, and then:

chmod +x cpplint.py
sudo mv cpplint.py /usr/local/bin

Now, you can style-check a file using cpplint.py as an executable:

cpplint.py filename

Alternately, you could run it using Python:

python cpplint.py filename

Using cpplint

We've agreed to turn off certain warnings. At present, you may run with:

cpplint.py --filter=-runtime/references,-build/header_guard --extensions=cpp,hpp

Additional Files

Produce and turn in a Makefile for building your class.

The executable that the Makefile builds must be called ps5a. This should be the result of linking your test.o and your RingBuffer.o.

Produce and turn in a plain-text ps5a-readme.txt file that explains what you have done.

In particular, describe:

  • how you implemented the ring buffer (e.g. per the Princeton guidance, or some other way)
  • exactly what works or doesn't work

Submit your work

You should be submitting at least five files:

  1. RingBuffer.cpp
  2. RingBuffer.hpp
  3. test.cpp (this gets downloaded as ps5a-test.cpp, rename it to test.cpp)
  4. Makefile
  5. ps5a-readme.txt

If you create a main.cpp with printf-style tests, you may submit that as well.

Place the files in subdirectory called ps5a, and archive with:

tar czvf <archive-file-name>.tar.gz ps5a

Submit the archive via Bottlenose:

Martin section (201): https://grader.cs.uml.edu/assignments/493
Grinberg section (202): https://grader.cs.uml.edu/assignments/494

Grading rubric

FeatureValueComment
core implementation4full & correct implementation=4 pts; nearly complete=3pts; part way=2 pts; started=1 pt
Makefile2Makefile included
your own test.cpp4should test that you:
  generate std::invalid_argument exception on bad constructor;
  don't generate exception on good constructor;
  enqueue, dequeue, and peek work;
  generate std::runtime_error when calling enqueue on full buffer;
  generate std::runtime_error when calling dequeue or peek on empty buffer.
cpplint2Your source files pass the style checks implemented in cpplint
readme.txt4Readme should say something meaningful about what you accomplished
  1 point for explaining how you tested your implementation
  1 point for explaining the exceptions you implemented
  2 points for correctly explaining the time and space performance of your RB implementation
Total16 
Edit - History - Print - Recent Changes - Search
Page last modified on March 27, 2015, at 09:58 AM