Programming Task 7


Time Estimate: 4 hours

Jump to current week
Requirements

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 the previous task, you wrote code to load song and movie data from files into data structures. In this task we'll use this data, and the fact that Song and Movie both inherit from Ratable, to write code that will find the top-rated Songs and Movies. To this end, you will implement the following specs.

  • A class named MediaLibrary in the ratings package.
    • MediaLibrary has a constructor that takes no parameters
    • MediaLibrary has a method named populateLibrary that returns void and takes 3 Strings as parameters representing filenames for songs with ratings, movies (title and cast), then movie ratings in this order. These three files will match the three static methods you've written in your FileReader class. The expected behavior of this method will match the expected behavior of those three methods. This method will read all the data from all three files and store all the Songs and Movies as part of the state of the MediaLibrary object
    • MediaLibrary has a method named topKRatables that takes an int and returns an ArrayList of Ratables. This method will return the top k ratables that have been loaded using the populateLibrary method where k is the input int (eg. topKRatables(10) returns a top 10 list). The ratables will be ranked by their bayesian average rating with 2 extra ratings of value 3 in decreasing order (eg. The ratable with the highest bayesian average should be at index 0). If k is greater than the number of ratables, return all ratables (eg. If k is 100 and there are only 3 ratables in the library, return all 3).
    • Note: All these methods should be tested together. To test whether populateLibrary reads the data properly, you must call the topKRatables as there is no other way - that is defined in this document and can be used in testing - to access the state of the MediaLibrary object
    • Note: Throughout your testing, you may assume that Songs and Movies have unique titles. When testing topKRatables, if the returned ArrayList contains the correct titles in the correct order, your test should pass (ie. you don't have to check any other instance variables like the ratings linked list, song ids, artists, or cast members)
    • Note: You don't have to write tests where any 2 songs or movies have the same bayesian average rating. This would be tedious to test since the order can depend on truncation errors


Testing Utilities


TestClasses3: Create a class named TestClasses3 in the tests package and write the following testing utility method in this class.

  • compareRatableArrayLists - Write a method named compareRatableArrayLists in the tests.TestFiles class that:
    • Takes [references to] 2 ArrayList<Ratable> objects as parameters
    • Returns a boolean that is true if both ArrayLists contain Ratables with the same titles in the same order. The method either returns false, or fails a JUnit assert, if the ArrayLists do not contain exactly the same songs

Note: This utility method is simpler than the one from the previous task. Don't overthink it.



Testing Requirements


Write tests for the MediaLibrary class by calling populateLibrary, then check that topKRatables returns the expected songs and movies in the expected order

Testing with files should follow the same structure as task 6 (eg. all test files should be in the "data" directory)

Note: Do not add spaces in your testing filename. Use underscores like in the examples above if you want to use filenames with multiple words.



Programming Requirements


Implement all the methods of the MediaLibrary class.



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.

  1. 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
  2. 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
  3. 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
  4. 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.