Answered step by step
Verified Expert Solution
Link Copied!

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 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.:
image text in transcribed

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

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions