Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to write testing code to go through the code below to prove these are all correct. Utopian tree growth is a well-know, frequently-used

I need to write testing code to go through the code below to prove these are all correct.

Utopian tree growth is a well-know, frequently-used interview question that supposedly eliminates job candidates who are not "good" programmers. For this question, the candidate must write a method with one parameter. The method returns the height of a tree exhibiting a "perfect" pattern of growth. The number of growth cycles is 0, then the tree has a height of 0. If the number of cycles is 1, then the tree has a height of 1. In this idealized world, trees go through two growth cycles per year. During the first cycle of the year (e.g., growth cycles 2, 4, 6, etc.), the tree height increases by 1. During the second cycle of the year (e.g., growth cycles 3, 5, 7, etc.), the tree doubles in height. Were this somehow useful, remotely interesting, or not so well known, it might at least be useful for interviews question. But it exists and is used and so provides good practice for your first chance at writing JUnit test cases.

Download the JAR file containing my CORRECT solution. You should follow these directions to add the JAR file to your project. You then need to write a class, named TreeGrowthTest, which contains JUnit test cases that validates my code. Each of your tests should be in its own method and, by running all of the tests, executes every line in your test class and my solution ("provide 100% coverage") . Because the number of lines executed cannot be checked on your computer, you will not be penalized for multiple submissions to Autolab on this question.image text in transcribed

During job interviews, candidates are often asked to both write solutions to small, useless problems and then to 5 write test cases verifying that other small, useless problems work. This problem provides an example of a small 6 useless problem candidates would be required to write test cases making certain every possible situation is handled. 8 author Matthew Hertz 10 public class TreeGrowth { 12 This method computes the height of a tree exhibiting a "perfect" pattern of growth. If the number of 13 growth cycles is 0, then the tree has a height of 0. If the number of cycles is 1, then the tree has a height of 1 14In this idealized world, trees go through two growth cycles per year. During the first cycle of the year (e.g., 15 growth cycles 2, 4, 6, etc.), the tree height increases by 1. During the second cycle of the year (e.g., growth 16 cycles 3, 5, 7, etc.), the tree doubles in height 17 18 @param cycles Number of cycles of growth for this tree 19 @return Height of the tree after the specified number of growth cycles. 20 */ 21 public int computeTreeHeight(int cycles) 22 if (cycles 0) 23 24 else if (cycles1) 25 26 27 28 for (int i = 1; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions