Programming Task 1


Time Estimate: 5 hours

Jump to current week
Requirements

Project Structure


GitHub Repository link: https://github.com/jessehartloff/CSE116-Project

  1. Clone the starter code from the repository into a new IntelliJ project
  2. Make sure the src folder is marked as the source root (Right click the src folder, choose “mark directory as” and choose sources root)

Once you have the project opened in IntelliJ, you'll see a src folder containing 2 Java packages named ratings and tests. Your code for this Task will go in the ratings.ProblemSet class, while your testing will go in tests.TestProblemSet. For now, the rest of the classes can be ignored, though they will be used in future Tasks.

To submit your project, create a zip file containing your entire project and submit it to Autolab. (Click file -> export -> Project to Zip File, though there may be slight differences to this across OSes and versions)



Testing Requirements


This is primarily a testing task and your feedback in Autolab will begin by checking your tests. You will write tests for 3 different methods. All of your testing will be in the tests.TestProblemSet class. You are strongly encouraged to write many individual tests in this one class.

  1. average
    • Add tests to the tests.TestProblemSet class that will test a static method named average in the ratings.ProblemSet class
    • The average method will take an ArrayList of Doubles as a parameter and returns the average of the values in the ArrayList as a double
    • If the ArrayList is empty, the method should return 0.0
    • Examples:
      • average([1.0,2.0,3.0]) returns 2.0
      • average([-5.0,5.0]) returns 0.0
      • average([6.5,6.5,8.5,8.5]) returns 7.5
      • average([]) returns 0.0
  2. sumOfDigits
    • Add tests to the tests.TestProblemSet class that will test a static method named sumOfDigits in the ratings.ProblemSet class
    • The sumOfDigits method will take an int as a parameter and returns the sum of the digits of the input as an int
    • Examples:
      • sumOfDigits(123) returns 6
      • sumOfDigits(57) returns 12
      • sumOfDigits(-36) returns 9
  3. bestKey
    • Add tests to the tests.TestProblemSet class that will test a static method named bestKey in the ratings.ProblemSet class
    • The bestKey method will take a HashMap of Strings to Integers as a parameter and returns a key mapping to the largest Integer
    • If the HashMap is empty, the method should return the empty String
    • The method may break ties arbitrarily. When you write a test case where there are multiple correct solutions, you must accept any of these as correct return values in your test
    • Examples:
      • bestKey({"CSE": 100, "MTH": 90, "MGT": 10}) returns "CSE"
      • bestKey({"cat": 5, "dog": 5, "fox": 4}) can return either "cat" or "dog"
      • bestKey({}) returns ""


Programming Requirements


Implement the three methods that you've tested. You can, and should, run your tests while completing your code to check if it is correct.



Autolab Feedback


The feedback in Autolab will be given in 3 phases. If you don't complete a phase, then feedback for the following phase(s) will not be given.

  1. 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.
  2. 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
  3. 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 3 phases, you will have completed this Task and Autolab will confirm this with a score of 1.0 for complete.