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 1- class Node
Create two files:
linkedlist.py and test_linkedlist.py. Implement unittests and functionality for a
Node class as described below.
Node
item: Any
link: Node | None
init (self, item: Any, link: Optional[Node])-> None
repr_(self) str
Figure 1: 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.
init(self, 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, e.g. Node(Jake)
_ This is a dunder method: ()
TDD Flow:
init
Red: test_linkedlist.py, TestNode class:
Create a node, and assert it has the correct attributes, e.g.
node1=Node(dots)
self . assertEqual (node1.item, ...)
self . assertEqual (node1.link, ...)
Green:
linkedlist.py, Node class: implement _-
repr
Red: test_linkedlist.py, TestNode class:
Create a node, and assert it has the correct repr () return, e.g.
node1.)
self .assertEqual (repr (node1), "Node(...)")
Green:
linkedlist.py, Node class: implement
Readability Note
You should (almost) always call dunder methods using their "magic" syntax. E.g.:
 Create the fundamental Node and LinkedList classes using test driven development

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!