Kotlinlearncs.online LogoJava
Return to List

Test Writing: Accounting Calculator

Created By: Miguel Fernandez
/ Version: 2021.7.0

The Accounting firm LambdaCalculator is running out of money. In the past few months, they've struggled to find new clients, and as a result they are looking at laying off staff. They've hired you to build some software that fulfills the role of their accountants. As the first step, you will write some code that calculates the gross profit (total revenue minus total expenses) for monthly financial reports.

Write a function called calculateGrossProfit that takes in two int[] parameters, the revenue for each day of a month then the expenses for each day of a month, and returns the gross profit (revenues minus expenses) as an int. You may assume that both passed arrays will not be null and the same length.

Here's an example of how your class should behave:

Readings:

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 Java's assert method