Completed method for triangle and rectangle, and testing for triangle