Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 3 : Python Benchmarking, Logging, and Unit Testing Purpose : Practice using Python benchmarking, logging, and unit testing . Grades will start at 100%

Assignment 3: Python Benchmarking, Logging, and Unit Testing

Purpose: Practice using Python benchmarking, logging, and unit testing.

Grades will start at 100% and then deductions made for errors preventing the correct answer to be calculated, or if the solution does not use Python classes, inheritance and overloading.

Individual Assignment: Hand-In your own Python source code (submit to Assignment object in Moodle). Feel free to collaborate in your groups, but dont copy the groups solution. Copied solutions (both originator and user) will receive a grade of 0.

Due in 2 weeks (allows us to resolve any doubts during the following class).

Name your zip file: [your name]+[your ID]+assignment 3.zip

Use only standard Python libraries (i.e. timeit, logging, unittest, etc. and native Python code) to solve.

Assignment code files will be file-compared with the class. Identical or nearly identical submissions will both receive 0.

Problem:

Revisit your Assignment 2 (if you need Assignment 2 code let me know) and:

Instrument your code by benchmarking to time the duration of long calculations and then both display them to console output and log them in a logfile
Log events (at least 1 from each of the classes Info, Warning, Error, Exception) to a log file
In a separate sub-package named test, add unit tests that run as a separate target in your project, and use at least 1 of each class: AssertEqual or AssertNotEqual, AssertTrue or AssertFalse, AssertIsor AssertIsNot, AssertIsNone or AssertIsNotNone, AssertIn or AssertNotIn, assertIsInstance or assertIsNotInstance, assertRaises, and assertGreateror assertLess, and any other assert method you would like to use as a unit test

Example Code Snippet (doesnt run, has defects but outlines an approach, provided as a starting point, feel free to modify, improve and create your approach)

from unittest import TestCase

import DirectedEdge

class TestDirectedEdge(TestCase):

def setUp(self):

self.directed_edge0 = DirectedEdge.DirectedEdge('A', 1)

got_expected_assertion = False

try:

self.directed_edge1 = DirectedEdge.DirectedEdge('B', 0)

except AssertionError as e:

got_expected_assertion = True

if not got_expected_assertion:

self.fail()

.

def test_get_to_vertex(self):

self.assertGreater(len(self.directed_edge0.get_to_vertex()), 0)

self.assertGreater(len(self.directed_edge3.get_to_vertex()), 0)

.

class TestProblem(TestCase):

def setUp(self):

directed_graph = DirectedGraph.DirectedGraph()

got_expected_assertion = False

try:

Problem.Problem(-1, directed_graph)

except AssertionError as e:

got_expected_assertion = True

if not got_expected_assertion:

self.fail()

got_expected_assertion = False

try:

Problem.Problem(1, directed_graph)

except AssertionError as e:

got_expected_assertion = True

if not got_expected_assertion:

self.fail()

Rectify the errors and run the code

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

5.2 Describe the key features of panic disorder.

Answered: 1 week ago