Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started