Starting from:
$35

$29

Assignment 1 Solution

Objectives

    • Practice developing effective unit tests

    • Practice implementing unit tests with JUnit

    • Practice working with TDD

Preparation:

Clone the code on the repository https://git.cs.dal.ca/courses/2021-summer/csci-5308/assignment1/ronnie

Problem Statement

You have three main tasks in this assignment:

    • Create a set of unit tests using for the provided classes which are already developed

    • The correctness of the code using your unit tests and if you find any bug fix it.

    • Use TDD to design unit tests and develop the parts of code that are missing, use the specification on the comments to do this.

Background

You have inherited some buggy and incomplete code for computing shortest path solutions to the board game Ticket to Ride. The previous developer left the company, so it is your job to finish the software. Your boss has hired you to write a comprehensive set of tests for part of the codebase.

Given a game board of rail segments and a list of routes (pairs of cities), the code is supposed to compute the total cost of building a network between the given routes, assuming that the shortest distance for each route is chosen. This can be computed by computing shortest paths for each route using Dijkstra’s shortest path algorithm.

You will be provided with a partial codebase for distance computation, a specification, some JUnit5 test class, and a list of classes for which you are to create unit tests. Your job is to create the test suite, identify and fix the bugs (if any) and finish the methods not implemented in the classes.




















Note that the code you are provided does not have a main method and does not have the method implementing Dijkstra’s shortest path algorithm. These will be provided in a later assignments. You only need to write unit tests and finish up the classes already started, not code for the Ticket to Ride problem in this assignment.

Task

    1. Read the specification of what the code is supposed to do in docs/specification.pdf

    2. Create a set of unit tests using JUnit5 using the provided classes. Remember that each class needs to have its own test class, with several tests to check the implemented methods.

        ◦ City.java

        ◦ Link.java

        ◦ CityComparator.java
    3. Implement a separate test class for each of the above target classes. Some sample empty tests and real tests have been provided. For each test class

            a. Create as many tests for each method of each class as needed. But remember, each method must have at least one unit test.

            b. Each test should provide an appropriate message if it fails.

            c. Use good formatting and documentation in your tests, just like for any source code.

    4. All the test classes should compile and be runnable in IntelliJ. If your test classes do not compile, you will receive 0 on the assignment.

    5. Record all detected errors in a file called errors.txt in the docs directory. Each error should have the following information:

            a. Class name

            b. Method name

            c. Test name that caught the error

            d. Message that the test method generated

This information will be used to assess the number of errors found by your tests. An example is provided.
    6. Commit as you go and add a clear message about what you did, e.g., finished creating the unit test for setCity() method, then commit with the message about this part of your work before moving to something else.

    7. Push back your work to YOUR remote repository, not to the one that you cloned. Everyone has their own repository to deliver this assignment, e.g., https://git.cs.dal.ca/courses/2021-summer/csci-5308/assignment1/yourscid.

    8. Remember to check that all your files have been submitted using the web interface to git.

Submission

All the code should be committed and pushed back to the remote Git repository.

Grading

The following grading scheme will be used:

Task


Thoroughness

(30%)



Overlap

(20%)


Error Detection (20%)




Code Clarity

(20%)







Separate

commits

(10%)


4/4
3/4
All or nearly all
Most test cases
test cases are
are covered
covered


Nearly all tests
Most tests have
have a purpose.
a purpose. There
There are very
are a few
few redundant
redundant tests.
tests.


All or nearly all
Most of the
errors are
errors are
detected.

detected.
Code
looks
Code looks ok,
professional,
but has a few
follows
style
inconsistencies.
guidelines and
Mostly follows
has  very
few
style guidelines.
issues. Code is
Code is
very readable.
readable.
Used
a
Used a separate
separate

commit to
commit
to
almost all
every  change
changes made
made



2/4


Some of test cases are covered

At least half the tests have a purpose. Half the tests are redundant.

Half the errors are detected.


Code is sloppy with many inconsistencies. Sometimes follows style guidelines and is a little hard to read

Used a separate commit to half of the changes made

1/4    0/4


Few test cases    No test cases


are covered    created

Most of the tests    All the tests test


test the same    the same

condition.    condition.



Few of the errors    None of the


are detected.    errors are

detected.


Code is very    Code is illegible.


sloppy and does

not follow style

guidelines. Code

is hard to read.



Sometimes used    Has not used


a separate    separate

commit to the    commits.

changes made

More products