Kotlinlearncs.online LogoJava
Return to List

Test Writing: Double Array Range and Sum String

Created By: CEO
/ Version: 2023.8.0

Let's compute a few summary statistics on a dataset. Create a method named summarizeValues that accepts a non-empty DoubleArray.

Compute the mean and the range of the dataset and return a String in the following format:

Mean: <mean>
Range: <range>

Where <mean> and <range> are the mean and range of the dataset computed by your method.

Round the values to 2 decimal points using a method round which accepts a Double value. For example, round(3.33542) would return 3.34.

Given the array {1.0, 2.0, 4.0}, your method should return:

Mean: 2.33
Range: 3.0

(Note that Kotlin's multi-line string literal will not work correctly for this problem, so you'll need to insert the newline manually.)

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Kotlin's assert or check methods