Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Purpose: Completing a test script for an ADT. Degree of Difficulty: Easy. On the course Moodle, you'll find: The file Statistica-py.which is an ADT covered

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Purpose: Completing a test script for an ADT. Degree of Difficulty: Easy. On the course Moodle, you'll find: The file Statistica-py.which is an ADT covered in class and in the readings. Foryour convenience, we removed some of the calculations and operations (eg. var () and sampvar (), that were not relevant to this exercise, which would have made testing too onerous. The file test_statistics.py. which is a test-script for the statistics ADT. This test script currently only implements a few basic tests. In this question you will complete the given test script Study the test script, observing that each operation gets tested, and sometimes the tests look into the ADT's data structure, and sometimes, the operations are used to help set up tests. You'll notice that there is exactly one test for each operation, which is inadequate. Design new test cases for the operations, considering: Black-box test cases. White-box test cases. Boundary test cases, and test case equivalence classes. Test coverage, and degrees of testing. Unit vs. integration testing. Running your test script on the given ADT should report no errors, and should display nothing except the message *** Test script completed ***'. What to Hand In A Python script named a3q3_testing.py containing your test script Be sure to include your name, NSID, student number, course number and laboratory section at the top of all documents. Evaluation 5 marks: Your test cases for Statistics.add () have good coverage. 5 marks: Your test cases for Statistics.mean () have good coverage. Abstract Data Types %23 # Defines the Statistics ADT # Calculate mean and variance. # statistics # Implementation # Do the calculations without storing all the data! # Uses a dictionary as a record to store three quantities: the number of data values added 'count': #3 'avg': the running average of the values added #3 # These values can be modified every time a new data value is # added, so that the mean and variance can be calculated quickly # as needed. This approach means that we do not need to store # the data values themselves, which could save a lot of space. # NOTE: This version of the Statistics ADT is simplified for # Assignment 3: all calculations relevant to variance are removed. def create(): Purpose: Create a Statistics record. Pre-conditions: (none) Post-conditions: a new record is allocated Return: A reference to a Statistics record. {} b['count'] # how many data values have been seen # the running average so far b['avg'] return b def create(): Purpose: Create a Statistics record. Pre-conditions: (none) Post-conditions: a new record is allocated Return: A reference to a Statistics record. {} b['count'] # how many data values have been seen # the running average so far b['avg'] return b def add(stat, value): Purpose: Use the given value in the calculation of statistics. Pre-Conditions: stat: a Statistics record value: the value to be added Post-Conditions: none Return: e stat['count'] += 1 stat['count'] # convenience diff = value stat['avg'] # convenience stat['avg'] += diff/k def mean(stat): Purpose: Return the mean of all the values seen so far. Pre-conditions: stat: the Statistics record Post-conditions: (none) Return: The mean of the data seen so far. Note: if no data has been seen, 0 returne This is clearly false. return stat['avg'] # Assignment 3: ADTS and Testing #test statistics # This script is a starter file for testing the Statistics ADT import Statistics as Stat # test Statistics.create() # create() has no parameters, so we only need one test case # but we can test several things about the statistics data structure test_create %3D {'inputs' : [], 'outputs':[0, e], 'reason' : 'Checking initial values'}, for t in test_create: for t in test_create: args_in = t['inputs'] # pointless, but keeps the pattern consistent expected t['outputs'] # create the Statistics data structure thing = Stat.create() %3D # we'Ll open the data structure in these tests # check the initial count if thing['count'] != expected[0]: print('Error in create(): expected count', expected[0], ' but found ', thing['count'], '--', t['reason']) # check the initial ave if thing['avg'] != expected[1]: print('Error in create(): expected avg', expected[1], ' but found ', thing['avg'], '--', t['reason']) # test Statistics.add() # these are integration tests test_add {'inputs': [0], # single value to be added 'outputs':[1, e], # [count, avg] 'reason' : 'No change to avg'}, # TODO Add more test cases test_add: args_in for t t['inputs'] expected t['outputs'] %3D # create the Statistics data structure Stat.create() thing %3D # now call add() Stat.add(thing, args_in[0]) # we'Ll open the data structure in these tests # check the count if thing['count'] != expected[0]: print('Error in add(): expected count', expected[0], ' but found', thing['count'], --', t['reason']) # check the ave if thing['avg'] != expected[1]: print('Error in add(): expected avg', expected[1], but found ', thing['avg'], '--', t['reason']) # test Statistics.mean() test mean = {'inputs': [0,0,0,0,0], # data values to be added "outputs':[5, 0], 'reason' : 'All zeroes'}, #[count, avg] # TODO Add more test cases for t in test_mean: t['inputs'] args_in expected = t['outputs'] # create the Statistics data structure Stat.create() thing %3D # add the give values to the for val in args_in: Stat.add(thing, val) # now call mean) result = Stat.mean(thing) # we'Ll open the data structure in these tests # check the count if thing['count'] != expected[0]: print('Error in add(): expected count', expected[0], but found ', thing['count'], '--', t['reason']) # check the ave if thing['avg'] != expected[1]: print('Error in add(): expected avg', expected[1], but found ', thing['avg'], '--', t['reason']) # check the ave if thing['avg'] != expected[1]: print('Error in add(): expected avg', expected[1], but found ', thing['avg'], '--', t['reason']) # check the result of mean() if result != expected[1]: print('Error in mean(): expected avg', expected[1], ' but found ', result, '--', t['reason']) **** Test script completed ***') print(' Purpose: Completing a test script for an ADT. Degree of Difficulty: Easy. On the course Moodle, you'll find: The file Statistica-py.which is an ADT covered in class and in the readings. Foryour convenience, we removed some of the calculations and operations (eg. var () and sampvar (), that were not relevant to this exercise, which would have made testing too onerous. The file test_statistics.py. which is a test-script for the statistics ADT. This test script currently only implements a few basic tests. In this question you will complete the given test script Study the test script, observing that each operation gets tested, and sometimes the tests look into the ADT's data structure, and sometimes, the operations are used to help set up tests. You'll notice that there is exactly one test for each operation, which is inadequate. Design new test cases for the operations, considering: Black-box test cases. White-box test cases. Boundary test cases, and test case equivalence classes. Test coverage, and degrees of testing. Unit vs. integration testing. Running your test script on the given ADT should report no errors, and should display nothing except the message *** Test script completed ***'. What to Hand In A Python script named a3q3_testing.py containing your test script Be sure to include your name, NSID, student number, course number and laboratory section at the top of all documents. Evaluation 5 marks: Your test cases for Statistics.add () have good coverage. 5 marks: Your test cases for Statistics.mean () have good coverage. Abstract Data Types %23 # Defines the Statistics ADT # Calculate mean and variance. # statistics # Implementation # Do the calculations without storing all the data! # Uses a dictionary as a record to store three quantities: the number of data values added 'count': #3 'avg': the running average of the values added #3 # These values can be modified every time a new data value is # added, so that the mean and variance can be calculated quickly # as needed. This approach means that we do not need to store # the data values themselves, which could save a lot of space. # NOTE: This version of the Statistics ADT is simplified for # Assignment 3: all calculations relevant to variance are removed. def create(): Purpose: Create a Statistics record. Pre-conditions: (none) Post-conditions: a new record is allocated Return: A reference to a Statistics record. {} b['count'] # how many data values have been seen # the running average so far b['avg'] return b def create(): Purpose: Create a Statistics record. Pre-conditions: (none) Post-conditions: a new record is allocated Return: A reference to a Statistics record. {} b['count'] # how many data values have been seen # the running average so far b['avg'] return b def add(stat, value): Purpose: Use the given value in the calculation of statistics. Pre-Conditions: stat: a Statistics record value: the value to be added Post-Conditions: none Return: e stat['count'] += 1 stat['count'] # convenience diff = value stat['avg'] # convenience stat['avg'] += diff/k def mean(stat): Purpose: Return the mean of all the values seen so far. Pre-conditions: stat: the Statistics record Post-conditions: (none) Return: The mean of the data seen so far. Note: if no data has been seen, 0 returne This is clearly false. return stat['avg'] # Assignment 3: ADTS and Testing #test statistics # This script is a starter file for testing the Statistics ADT import Statistics as Stat # test Statistics.create() # create() has no parameters, so we only need one test case # but we can test several things about the statistics data structure test_create %3D {'inputs' : [], 'outputs':[0, e], 'reason' : 'Checking initial values'}, for t in test_create: for t in test_create: args_in = t['inputs'] # pointless, but keeps the pattern consistent expected t['outputs'] # create the Statistics data structure thing = Stat.create() %3D # we'Ll open the data structure in these tests # check the initial count if thing['count'] != expected[0]: print('Error in create(): expected count', expected[0], ' but found ', thing['count'], '--', t['reason']) # check the initial ave if thing['avg'] != expected[1]: print('Error in create(): expected avg', expected[1], ' but found ', thing['avg'], '--', t['reason']) # test Statistics.add() # these are integration tests test_add {'inputs': [0], # single value to be added 'outputs':[1, e], # [count, avg] 'reason' : 'No change to avg'}, # TODO Add more test cases test_add: args_in for t t['inputs'] expected t['outputs'] %3D # create the Statistics data structure Stat.create() thing %3D # now call add() Stat.add(thing, args_in[0]) # we'Ll open the data structure in these tests # check the count if thing['count'] != expected[0]: print('Error in add(): expected count', expected[0], ' but found', thing['count'], --', t['reason']) # check the ave if thing['avg'] != expected[1]: print('Error in add(): expected avg', expected[1], but found ', thing['avg'], '--', t['reason']) # test Statistics.mean() test mean = {'inputs': [0,0,0,0,0], # data values to be added "outputs':[5, 0], 'reason' : 'All zeroes'}, #[count, avg] # TODO Add more test cases for t in test_mean: t['inputs'] args_in expected = t['outputs'] # create the Statistics data structure Stat.create() thing %3D # add the give values to the for val in args_in: Stat.add(thing, val) # now call mean) result = Stat.mean(thing) # we'Ll open the data structure in these tests # check the count if thing['count'] != expected[0]: print('Error in add(): expected count', expected[0], but found ', thing['count'], '--', t['reason']) # check the ave if thing['avg'] != expected[1]: print('Error in add(): expected avg', expected[1], but found ', thing['avg'], '--', t['reason']) # check the ave if thing['avg'] != expected[1]: print('Error in add(): expected avg', expected[1], but found ', thing['avg'], '--', t['reason']) # check the result of mean() if result != expected[1]: print('Error in mean(): expected avg', expected[1], ' but found ', result, '--', t['reason']) **** Test script completed ***') print(

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

More Books

Students also viewed these Databases questions

Question

What type of postprocessing is required for ID processes?

Answered: 1 week ago

Question

What are the objectives of job evaluation ?

Answered: 1 week ago

Question

Write a note on job design.

Answered: 1 week ago

Question

Compute the derivative of f(x)cos(-4/5x)

Answered: 1 week ago

Question

Discuss the process involved in selection.

Answered: 1 week ago