- 作业标题:CSCI 2134 - Software Development - lab 6 Exceptions and Assertions
- 课程名称:Dalhouse University CSCI 2134 Software Development
- 完成周期:1天
Objective
In this lab, you will work on your own or with another student to improve the robustness of
existing code using exceptions and assertions.
##Preparation
- Ensure that you have your Integrated Development Editor (IDE) installed.
- Ensure that you are able to write and run a JUnit test case in the IDE. You will not have the
time to both debug your IDE environment and complete the lab task within the lab time.
The lab time should be able to concentrate on the lab task. - Clone the Lab 6 repo: https://git.cs.dal.ca/courses/2021-fall/csci-2134/lab6/????.git
where ???? is your CSID. - Review the provided code listed in the Resources section below by reading the code of the
class you will be fortifying (Matrix.java) and the unit tests (MatrixTest.java).
These files are located in the src and test directories of the cloned project. - You may also wish to read the provided primer on matrix operations, found in the docs
directory.
Resources
• Primer on matrices and example assertion_list.txt in the docs directory of the
Lab 6 repository.
• Code base to be debugged is in the src directory of the Lab 6 repository.
• Test code is in the test directory of the Lab 6 repository.
Procedure
Set-up
- Open the project you created in preparation for this lab
Part 1: Add Exceptions to Matrix.java - Review the code for getElem() and the constructors in Matrix.java as an example of
what you are being asked to do. - For each of following methods review the updated specifications in Matrix.java.
Instead of returning null, the method should be modified to throw an exception.
Implement this change in the following methods:
o add()
o multiplyWithScalar()
o multiplyWithMatrix()
o setElem()
Run the regression tests (MatrixTest.java) to ensure that no tests have failed.
Commit and push back to the repository
Part 2: Add Tests to MatrixTest.java
Review the code for getElemIndexOutOfBounds() in MatrixTest.java as an
example of what you are being asked to do.For each of the methods that you modified in Matrix.java, add a test method to
MatrixTest.java (named using the same pattern as for getElem(). These methods should
test that the exceptions are being properly thrown.Commit and push the fix back to the repository.
Part 3: Assertions
- Review the methods in Matrix.java. Determine three (3) places in the code where an assert
statement would be helpful. See the write() method in Matrix.java for an example.
Note: placing the same assertion in multiple methods still only counts as one assertion. J - Note the suggested locations in the file docs/assertion_list.txt. Include the
method, the line number, and assertion condition - Add the assertion to the code
- Commit and push the fix back to the repository.
Grading
The lab will be marked out of 4 points
。。。