Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using python, if you need any additional information please ask me in the comments. Thank you ! The file a3q2.py contains three functions, which are

Using python, if you need any additional information please ask me in the comments. Thank you !

image text in transcribed

image text in transcribed

image 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]. rendup ( 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 ged() 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 15 16 17 def newtonraphson(x): " Add the doc-string! root = 1 while abs(x - root * root) > 0.00001: root = (x/root + root) / 2.0 return root 18 19 20 21 22 23 III 1 24 25 26 def ged(a, b): Add the doc-string! while a #b: if a > b: a = a - b else: b = b - a print(a) 27 28 29 A 30 A 31 32 33 34 35 36 = [] 37 38 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[e][e] triangle triangle[1:] return (size, triangle) 39 40 41 42 43 44 45 46 11 Il 47 48 49 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() 50 51 52 A 53 p 1 1 1 121 1 331 1 46 41 15 10 10 51 6 15 201561

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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions