Kotlinlearncs.online LogoJava
Return to List

Test Writing: Right Triangle Shape

Created By: Geoffrey Challen
/ Version: 2020.6.0

Create and complete the implementation of the RightTriangle class. Your class should be public, not final and not abstract, inherit from the Shape class, and provide the following methods:

  1. Constructor that takes a double parameter. Creates a new RightTriangle with the passed side length. You can assume that the passed size is greater than zero. You should call the Shape constructor and pass it the String "righttriangle" to identify the type of this shape.
  2. Public instance method area that takes no arguments and returns a double. Return the area of this shape: side * side * 0.5.
  3. Override public boolean equals(Object other). Return true if other is a RightTriangle with the same side length, and false otherwise. Note that other may be null or not a RightTriangle.

Finally, note that your class should not expose any of its internal state publicly.

Test Design Challenge

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

  • Provide a public class named TestRightTriangle with a single non-private class 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