Question: Consider the following code snippet, which (I think) is valid in a C++/Java-esque language: string toString(PlantBasedFood f) { switch(f.type) { case Apple: return ((Apple) f).


Consider the following code snippet, which (I think) is valid in a C++/Java-esque language: string toString(PlantBasedFood f) { switch(f.type) { case Apple: return ((Apple) f). AppleString(); case Banana: return ((Banana) f).BananaString(); case Carrot: return ((Carrot) f).CarrotString(); case Potato: return ((Potato) f).PotatoString(); } You can imagine that the code base is full of switch statements like this. 1. What is the impact of this style on the test-ability of the code base? For example, how many distinct inputs are needed to achieve full line coverage of this method? Full branch coverage? (2 points) 2. Describe how you could use polymorphism to reduce the number of inputs needed to achieve full line coverage of this method. (4 points) 3. Would this change be an improvement? Why or why not? (2 points)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
