Question: Create the fundamental Node and LinkedList classes using test driven development ( TDD ) . Part 1 - class Node Create two files: linkedlist.py and
Create the fundamental Node and LinkedList classes using test driven development TDD
Part class Node
Create two files:
linkedlist.py and testlinkedlist.py Implement unittests and functionality for a
Node class as described below.
Node
item: Any
link: Node None
init self item: Any, link: OptionalNode None
reprself str
Figure : Class diagram for Node. Note the use of expected types after colons. Node I None denotes it
can be a Node object or the None object. Optional Node means there is an optional Node parameter that
defaults to None.
initself item:Any, link:Optional Node None
Creates a new Node object. link is either another Node or the None object
self str
Returns a string representaiton of the object, eg NodeJake
This is a dunder method:
TDD Flow:
init
Red: testlinkedlist.py TestNode class:
Create a node, and assert it has the correct attributes, eg
nodeNode
self assertEqual nodeitem,
self assertEqual nodelink,
Green:
linkedlist.py Node class: implement
repr
Red: testlinkedlist.py TestNode class:
Create a node, and assert it has the correct repr return, eg
node
self assertEqual repr node "Node
Green:
linkedlist.py Node class: implement
Readability Note
You should almost always call dunder methods using their "magic" syntax. Eg:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
