Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Urgent!!! Purpose: To practice using blackbox testing without seeing a function's code Degree of Difficulty: Easy Black box tests are typically best written BEFORE you

Urgent!!! image text in transcribed
image text in transcribed
image text in transcribed
Purpose: To practice using blackbox testing without seeing a function's code Degree of Difficulty: Easy Black box tests are typically best written BEFORE you even start writing the function they are intended to test. For this question, you will write a series of black box tests for a function that you never write or see yourself. The recentTrend() function The function you are testing is called recentTrend(). The function accepts a single parameter, which is a list of integers. The function should return the most common value among the last 20 elements of the list (ie, the 20 values at the END of the list). Some special cases for the return value: - If the list is empty (i.e. []), the value None should be returned - If the list has fewer than 20 elements, it should just return the most common value - If there is a tie for the most common value, then the largest value from among those tied should be returned Remember you are not writing this function. It is provided in file testing_blackbox_recentTrend.py. You don't even need to read or understand the code of this function. You just need to understand what it is supposed to do so that you can write effective test cases for it. Some very basic knowledge of list e.g. [1, 2. 3] is a list of three elements. These elements are all integers: 1, 2, and 3. The last two elements are 2 and 3. Write a test driver Write a test driver that contains several tests for the recentTrend () function. A starter file testing_blackbox. recentTrend_testdriver_starter.py is provided that contains an example of a single test case. Add additional tests to this file, following the example of the textbook. Place testing_blackbox_recent Trend.py and the provided starter file in the same directory so the function recent Trend can be imported correctly. You can directly work on the starter file to write your test driver but make sure you change its name to a3q1v1_testdriver.py. Choose your test cases thoughtfully to cover a range of possible situations. Do NOT bother with test cases that use incorrect data types (i.e. passing in something other than a list, or a list of booleans instead of a Uist of integers). Instead, focus on tests to expose any possible errors in the function's logic. Exactly how many test cases to use is up to you; include as many as you think you need to discover any errors in the function. def recentTrend(L): "II" Returns the most common value (i.e. the mode) from among the LAST 20 elements af. the list L. If there is a tie for most common element, then return the highest value from among those tied. L: a list of integers return: The most common value from among the last 20 elements of L; or None if L is empty if .egn (L)=0 : return None counts ={} last20 ={[20:] mode = last20[0] for i in last20: if i in counts: counts [i]+=1 else: counts [i]=1 if counts [i]>= counts [mode]: mode =1 return mode testing_blackbox_recentTrend_testdriver_starter.py from testing_blackbox_recentTrend import recentTrend \# i.e. the recentTrend () function is sitting in a file called "test.ing b.lackkox rescentires... Ry." \# The empty list is a special case, so always test it! test = [] expected = None result = recentTrend ( test ) if result != expected: print("Testing recentTrend() with", test, " Expected:", expected, "Got: ", result) \#TODO: Expand this file with several more tests

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

Students also viewed these Databases questions

Question

please dont use chat gpt AI 2 0 0 . .

Answered: 1 week ago