Project Structure
You will continue to add functionality to your existing project from the previous task. There is
no new repository to clone.
Specification
In this task, you will test and implement the following specs.
Note: Use the provided ratings.datastructures.LinkedListNode class whenever a linked list [node] is needed. You do
not have to modify this class
ratings.Song - The following methods will be added to the Song class:
- A method named
addRating
that takes a [reference to] an object of type Rating as a
parameter (The type of the input is Rating) and returns void
-
This method will be called when a Reviewer rates this Song. All
added Ratings will be stored in a Linked List Node as an instance variable
-
This method will append new ratings to the end of the linked list
- Note: Since the Rating class checks for valid ratings, any added ratings can only have a rating
value of 1, 2, 3, 4, 5, or -1
- A method named
getRatings
that takes no parameters and returns a LinkedListNode of
Ratings
-
This method returns the head node of a Linked List containing all Ratings that have been
added to this Song
-
The returned Linked List node must return the Ratings in the order in which they were added.
For example, the first Rating that was added must be the first value in the list
-
If no ratings have been added, this method will return null
- A method named
setRatings
that takes a LinkedListNode of Ratings and returns void
-
This is a setter that replaces the stored linked list node of ratings (The instance variable)
with the one provided as a parameter. This assignment is done by reference (ie. any prior
ratings are replaced by the new list of ratings)
- A method named
averageRating
that takes no parameters and returns a double
-
This method returns the average of all the Ratings of this Song
-
If the list is empty, or only contains invalid ratings, the method returns 0.0
-
Any invalid rating, ratings of -1, will be ignored during this calculation (eg. A Song with
ratings [1, 5, -1, -1] has an average rating of 3.0)
- A method named
removeRatingByReviewer
that takes a Reviewer as a parameter and returns
void
-
This method will remove a Rating made for this Song by the given Reviewer by id
-
If the reviewer did not rate this song, this method has no effect
-
If the linked list contains multiple ratings by the reviewer, the method only removes
the first instance from the list (ie. the method does not have to handle removing
multiple ratings in a single call)
Note: You can see feedback in Autolab for your testing utilities and tests without completing the
programming portion of
this task, but you must at least create every method from this specification. You can "stub
out"
these methods by having them always return a fixed value, but they must exist so the grading code,
and your tests, can compile and run.
Testing Utilities
Create a class named TestDataStructures1
in the tests package (tests.TestDataStructures1) and write the
following utility method in that class (Note: Do not add the @Test annotation to this method since it is
not itself a test):
compareListsOfRatings
- Write a method named compareListsOfRatings in the tests.TestDataStructures1 class that:
-
Takes [references to] 2 LinkedListNode<Rating> objects as parameters and returns void
-
This method checks if the rating and reviewer id of all Ratings in both lists are
exactly the same and are in the same order. The method fails a JUnit
assert if the lists do not contain all the same values of their ratings objects in the same
order
-
Note that you cannot use == or .equals to compare 2 Ratings. You must check the rating and
reviewer id values separately
Testing Requirements
Write tests in the tests.TestDataStructures1 class for the averageRating and removeRatingByReviewer methods.
You may assume that the addRating, getRatings, and setRatings methods behave as expected. All 5 methods
will still be tested in the next phase, so it can help if you
test all 5 even though it's not explicitly required.
It is highly recommended that you create your expected linked lists and call your compareListsOfRatings to
check if getRatings returns a list with all the same values as the expected list
Programming Requirements
Implement all 5 methods from the specification in your Song class.
As you're writing this code, you should run your tests to see how you are progressing. It's
recommended that you write your tests first, submit to Autolab to make sure you have good testing,
then use those verified tests to check your code.
Autolab Feedback
The feedback in Autolab will be given in 4 phases. If you don't complete a phase, then feedback for
the following phase(s) will not be provided.
- Testing your testing utility method
-
Your testing utility method will be checked with a variety of test cases to
ensure
that
it makes all the required checks. This phase will ensure that your utility method is
accurate
before you start using it in your tests
- Running your tests on a correct solution
- Your tests will be run against a solution that is known to be correct. If your tests do
not pass this correct solution, there is an error somewhere in your tests that must be
fixed
before you can move on with the assignment. If your tests don't get past this check, you
should re-read this document and make sure you implemented your tests and code according
the specification. You should also make sure that if there are multiple correct outputs
to the input in your tests cases that you accept any of the outputs as correct
- Checking your tests for feature coverage
-
The next phase is to check if your tests check for a variety of features defined by
different inputs. You should write at least one test case for each feature to pass this
phase
-
Passing this phase does not necessarily mean that your testing is completely thorough.
Satisfying Autolab is the bare minimum testing requirement. Not all possible inputs are
checked, and it is sometimes possible to pass this phase
with weak testing. If you are struggling to earn credit for code that you believe
is correct, you should write more than the required tests
- Running my tests on your solution
-
Once Autolab is happy with your tests, it will run my tests against your code to check
it for correctness. If your testing is thorough, and your code passes your tests, then
you should pass this phase. If you pass your tests, but fail one of mine, it is an
indicator that you should write more tests to help expose your bug
Once you complete all 4 phases, you will have completed this Task and Autolab will confirm this
with a score of 1.0 for complete.