Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The file a3q2.py contains three functions, which are all more or less correct. In this question, you will be guided in the preparation of a

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

The file a3q2.py contains three functions, which are all more or less correct. In this question, you will be guided in the preparation of a test script to test the functions. newtonraphson(). This function implements a well-known algorithm for computing the square root of a non-negative number. 1. Study the function, and write an appropriate doc-string for it. 2. Design test cases for this function. There are 2 equivalence classes that are of interest. - Numbers between 0 and 1. The square root is bigger than the input number. - Numbers greater than 1. The square root is smaller than the input number. - There are two boundary cases: 0, and 1. Write test cases for function, considering the information above. Don't just test integers! ged(). This function implements a well-known algorithm for computing the greatest common divisor of two integers. For example, ged(27,6) = 3, since 3 is the largest integer that evenly divides 27 and 6. 1. Study the function, and write an appropriate doc-string for it. 2. Notice that the function prints to the console. It's a terrible design decision; it's nearly impossible to test console output from within Python. Before you test the function, modify the function to return the value instead. 3. Design test cases for this function. There are several equivalence classes of interest: - ab -b>a - a= b - What happens when a = 0 or b = 0? Is this okay? You may need to do some research to figure this out Write test cases for function, considering the information above. readtriangle(). This function opens a named file and reads the contents. An example of the kind of file that it reads is given, named triangle1.txt. Notice that the first line in the file is the length of the example. 1. Study the function, and write an appropriate doc-string for it. 2. Create a test script for this function. Testing a function like this is difficult because you don't want to type in correct result in your test script. It is hard to do test functions that read from a file completely. So here is a strategy that will help: - The function reads "Pascal Triangles". Create a couple more example files for testing. Smaller examples are fine! - Test that the returned size is correct for the example files. - Test that the length of the returned triangle is correct. Test that the elements of the triangle are also lists. To check if alist refers to a list, you can use the Python code type (alist) is list - this is a Boolean expression that returns True if alist was constructed by the list constructor. It will be true for lists, and false for everything else. remdup(). This function removes duplicates from a given list, keeping only the first occurrence of any duplicated value. For example, given the list [1, 2, 3, 1), remdup() will remove the second occurrence of 1. 1. Study the function, and write an appropriate doc-string for it. 2. Create a test script while considering the following equivalence classes: - No duplicates. - One duplicated item. - One duplicated item, with duplicates appearing sequentially - Multiple duplicated items appearing anywhere in the list. - The only boundary case is the empty list. What to Hand In A Python script named a3q2_nr.py with your test script for newtonraphson(). A Python script named a3q2_gcd.py with your test script for god(). A Python script named a3q2_tri.py with your test script for readtriangle(). A Python script named a3q2_dup.py with your test script for remdup(). A Python script named a3q2.py with the functions. You've added doc-strings, and modified gcd () as indicated. Be sure to include your name, NSID, student number, section number, and laboratory section at the top of all documents. Evaluation Function interface documentation. You added the doc-strings giving the correct information. - 2 marks for each function. Your test scripts perform the indicated testing. - 5 marks for each function. Marks will be deducted if * the testing does not include sufficient test cases * some of the equivalence classes are not tested. * the test script is overly convoluted or otherwise demonstrates poor style or design Eidef newtonraphson(x): 1. Add the doc-string! root = 1 while abs(x - root * root) > 0.00001: root = (x/root + root) / 2.0 return root def gcd(a, b): " Add the doc-string! while a != b: if a > b: a = a - b else: b = b - a print(a) A IF IT IF def read_triangle(filename): Add the doc-string! file = open(filename) triangle [] for line in file: line = line.rstrip().split() line [int(d) for d in line] triangle.append(line) file.close() size = triangle[0][0] triangle triangle[1:] return (size triangle). A IF IT IF def remdup (alist): " Add the doc-string! alist.reverse() for i in range(len(alist)-1): while alist[i] in alist[i+1:]: del alist[i] alist.reverse() a 7 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 1 6 15 20 15 6 1 5 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 2 1 1 1 1 The file a3q2.py contains three functions, which are all more or less correct. In this question, you will be guided in the preparation of a test script to test the functions. newtonraphson(). This function implements a well-known algorithm for computing the square root of a non-negative number. 1. Study the function, and write an appropriate doc-string for it. 2. Design test cases for this function. There are 2 equivalence classes that are of interest. - Numbers between 0 and 1. The square root is bigger than the input number. - Numbers greater than 1. The square root is smaller than the input number. - There are two boundary cases: 0, and 1. Write test cases for function, considering the information above. Don't just test integers! ged(). This function implements a well-known algorithm for computing the greatest common divisor of two integers. For example, ged(27,6) = 3, since 3 is the largest integer that evenly divides 27 and 6. 1. Study the function, and write an appropriate doc-string for it. 2. Notice that the function prints to the console. It's a terrible design decision; it's nearly impossible to test console output from within Python. Before you test the function, modify the function to return the value instead. 3. Design test cases for this function. There are several equivalence classes of interest: - ab -b>a - a= b - What happens when a = 0 or b = 0? Is this okay? You may need to do some research to figure this out Write test cases for function, considering the information above. readtriangle(). This function opens a named file and reads the contents. An example of the kind of file that it reads is given, named triangle1.txt. Notice that the first line in the file is the length of the example. 1. Study the function, and write an appropriate doc-string for it. 2. Create a test script for this function. Testing a function like this is difficult because you don't want to type in correct result in your test script. It is hard to do test functions that read from a file completely. So here is a strategy that will help: - The function reads "Pascal Triangles". Create a couple more example files for testing. Smaller examples are fine! - Test that the returned size is correct for the example files. - Test that the length of the returned triangle is correct. Test that the elements of the triangle are also lists. To check if alist refers to a list, you can use the Python code type (alist) is list - this is a Boolean expression that returns True if alist was constructed by the list constructor. It will be true for lists, and false for everything else. remdup(). This function removes duplicates from a given list, keeping only the first occurrence of any duplicated value. For example, given the list [1, 2, 3, 1), remdup() will remove the second occurrence of 1. 1. Study the function, and write an appropriate doc-string for it. 2. Create a test script while considering the following equivalence classes: - No duplicates. - One duplicated item. - One duplicated item, with duplicates appearing sequentially - Multiple duplicated items appearing anywhere in the list. - The only boundary case is the empty list. What to Hand In A Python script named a3q2_nr.py with your test script for newtonraphson(). A Python script named a3q2_gcd.py with your test script for god(). A Python script named a3q2_tri.py with your test script for readtriangle(). A Python script named a3q2_dup.py with your test script for remdup(). A Python script named a3q2.py with the functions. You've added doc-strings, and modified gcd () as indicated. Be sure to include your name, NSID, student number, section number, and laboratory section at the top of all documents. Evaluation Function interface documentation. You added the doc-strings giving the correct information. - 2 marks for each function. Your test scripts perform the indicated testing. - 5 marks for each function. Marks will be deducted if * the testing does not include sufficient test cases * some of the equivalence classes are not tested. * the test script is overly convoluted or otherwise demonstrates poor style or design Eidef newtonraphson(x): 1. Add the doc-string! root = 1 while abs(x - root * root) > 0.00001: root = (x/root + root) / 2.0 return root def gcd(a, b): " Add the doc-string! while a != b: if a > b: a = a - b else: b = b - a print(a) A IF IT IF def read_triangle(filename): Add the doc-string! file = open(filename) triangle [] for line in file: line = line.rstrip().split() line [int(d) for d in line] triangle.append(line) file.close() size = triangle[0][0] triangle triangle[1:] return (size triangle). A IF IT IF def remdup (alist): " Add the doc-string! alist.reverse() for i in range(len(alist)-1): while alist[i] in alist[i+1:]: del alist[i] alist.reverse() a 7 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 1 6 15 20 15 6 1 5 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 2 1 1 1 1

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_2

Step: 3

blur-text-image_3

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

Compare the current team to the ideal team.

Answered: 1 week ago

Question

Which of the following is NOT a relational operator? 1. =

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago