Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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).

image text in transcribed

image text in transcribed

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

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions