Question: This is using python 3.8, Please include docstring and keep the code clear and simple. This is for a 100 level CMPT class so in-depth

This is using python 3.8, Please include docstring and keep the code clear and simple. This is for a 100 level CMPT class so in-depth explanation would be helpful.

In this question write the function for the node change, write the bodies of the functions. You will also find a test script named testing.py. It has a bunch of test cases pre-written for you. Read it carefully, Thank you!!!

This is using python 3.8, Please include docstring and keep the code

testing.py

import node as N

clear and simple. This is for a 100 level CMPT class so

(c) (6 points) Implement the function replace_in(). The interface for the function is: def replace_in(node_chain, target, replacement): Purpose: Replaces each occurrence of the target value with the replacement Pre-conditions: :param node_chain: a node-chain, possibly empty :param target: a value that might appear in the node chain :param replacement: the value to replace the target Pre-conditions: Each occurrence of the target value in the chain is replaced with the replacement value. Return: None A demonstration of the application of the function is as follows: chain1 = N.node (1, N.node (1, N.node (9))) chain2 = N.node (2, N.node (7, N.node (15))) print('chaini before:', to_string(chaini)) replace_in (chain1, 1, 10) print('chain after:', to_string(chaini)) print('chain2 before:', to_string(chain2)) replace_in(chain2, 7, 1007) print('chain2 after:', to_string(chain2)) The output from the demonstration is as follows: chain1 before: [ 1 | *-]-->[ 1 | *-] --> [ 9/] chaint after: [ 10 | *-]-->[ 10 | * - ) -->[97] chain2 before: [ 2 | *-]-->[ 7 | *-]--> [ 15 /] chain2 after: [ 2 | *-]--> [ 1007 | * - ] -->[ 15 / ] # # #### UNIT TEST CASE: replace_in() #### test_item = "replace_in()" chain_in = None target_in = 1 repl_in = 0 expected_str = "EMPTY" reason = 'empty node chain' a5q2.replace_in(chain_in, target_in, repl_in) result_str = a5q1.to_string(chain_in) if result_str != expected_str: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result_str, expected_str, reason)) 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 #### UNIT TEST CASE: replace in #### chain_in = N.node(1) target_in = 1 repl_in = 0 expected_str = "[01/]" reason = 'node chain with one node, target replaced' a5q2.replace_in(chain_in, target_in, repl_in) result_str = a5q1.to_string(chain_in) if result_str != expected_str: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result_str, expected_str, reason)) #### UNIT TEST CASE: replace in #### chain_in = N.node(1) target_in = 0 repl_in = 1 expected_str = "[ 1 |/]" reason = 'node chain with one node, target not present' a5q2.replace_in(chain_in, target_in, repl_in) result_str = a5q1.to_string(chain_in) if result_str != expected_str: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result_str, expected_str, reason)) (c) (6 points) Implement the function replace_in(). The interface for the function is: def replace_in(node_chain, target, replacement): Purpose: Replaces each occurrence of the target value with the replacement Pre-conditions: :param node_chain: a node-chain, possibly empty :param target: a value that might appear in the node chain :param replacement: the value to replace the target Pre-conditions: Each occurrence of the target value in the chain is replaced with the replacement value. Return: None A demonstration of the application of the function is as follows: chain1 = N.node (1, N.node (1, N.node (9))) chain2 = N.node (2, N.node (7, N.node (15))) print('chaini before:', to_string(chaini)) replace_in (chain1, 1, 10) print('chain after:', to_string(chaini)) print('chain2 before:', to_string(chain2)) replace_in(chain2, 7, 1007) print('chain2 after:', to_string(chain2)) The output from the demonstration is as follows: chain1 before: [ 1 | *-]-->[ 1 | *-] --> [ 9/] chaint after: [ 10 | *-]-->[ 10 | * - ) -->[97] chain2 before: [ 2 | *-]-->[ 7 | *-]--> [ 15 /] chain2 after: [ 2 | *-]--> [ 1007 | * - ] -->[ 15 / ] # # #### UNIT TEST CASE: replace_in() #### test_item = "replace_in()" chain_in = None target_in = 1 repl_in = 0 expected_str = "EMPTY" reason = 'empty node chain' a5q2.replace_in(chain_in, target_in, repl_in) result_str = a5q1.to_string(chain_in) if result_str != expected_str: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result_str, expected_str, reason)) 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 #### UNIT TEST CASE: replace in #### chain_in = N.node(1) target_in = 1 repl_in = 0 expected_str = "[01/]" reason = 'node chain with one node, target replaced' a5q2.replace_in(chain_in, target_in, repl_in) result_str = a5q1.to_string(chain_in) if result_str != expected_str: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result_str, expected_str, reason)) #### UNIT TEST CASE: replace in #### chain_in = N.node(1) target_in = 0 repl_in = 1 expected_str = "[ 1 |/]" reason = 'node chain with one node, target not present' a5q2.replace_in(chain_in, target_in, repl_in) result_str = a5q1.to_string(chain_in) if result_str != expected_str: print('Test failed: {}: got "{}" expected "{}" -- {}'.format(test_item, result_str, expected_str, reason))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!