Now, we will write tests for the contains
method. Since contains
returns a boolean
, we can use the AssertTrue
and AssertFalse
checks to test it. In the testContains
method, write a test that creates a new Dataset
and adds several values, including 3.0
but not including 1.0
. Now, try adding the following assertions:
assertTrue(ds.contains(3.0));
assertFalse(ds.contains(1.0));
Play around with different values to make sure that your tests are working correctly.
Unfortunately we still have one more buggy method to find!
Implement tests for mean()
and median()
, then use the debugger to find and fix any bugs.
Recall that the mean of n
numbers x1
through xn
is (x1 + x2 + … + xn)/n
. In contrast, the median of n
numbers is the middle value if n
is odd and the mean of the two middle values if n
is even. E.g., the median of 5, 3, and 100 is 5. The median of 5, 3, 100, and 6 is 5.5.
At this point, all of your tests should pass. Yay!
Don’t forget to frequently save your progress periodically to GitHub using the add
, commit
, and push
commands with git.At this point, you should have submitted your solutions for DataSet.java
and DataSetTest.java
.