logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Dai AndrewsGeneral article writing
(5/5)

896 Answers

Hire Me
expert
Natsha TakiaFinance
(5/5)

923 Answers

Hire Me
expert
StatAnalytica ExpertTechnical writing
(5/5)

988 Answers

Hire Me
expert
Garardd BerwickData mining
(5/5)

916 Answers

Hire Me
Python Programming
(5/5)

Write a Dog class that will pass the tests contained in our test class.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

1. Doggie Day Care

I’ve given you the TestDog class  code

Do This: Write a Dog class that will pass the tests contained in our test class. Do NOT change

anything in our test class!

Your Dog class must provide the following methods to adequately pass our tests:

 * __init__ (takes a string name of dog, int age and Boolean indicating a purebred or not),

 * is_purebred (returns True or False depending on if the dog is a purebred)

 * clone (makes a non-mutated copy of the current object)

 * __str__ returns a string representation of the object

 * __eq__ returns True or False when comparing two instances of the Dog class

import unittest

from Dog import Dog

class TestDog(unittest.TestCase):

 ''' class to test all the methods of the Dog class

 imports from TestCase

 methods:

 * __init__,

 * is_purebred,

 * clone (makes a non-mutated copy of the current object)

 * __str__, represent the Dog as a string

 * __eq__, compare current object with another Dog. Are they equal?

 '''

 def test_init(self):

 d = Dog("Fido", 10, True)

 self.assertEqual(d.name, "Fido")

 self.assertEqual(d.age, 10)

 self.assertTrue(d.is_purebred)

  d2 = Dog("Fifi", 11, False)

 

 self.assertEqual(d2.name, "Fifi")

 self.assertEqual(d2.age, 11)

 self.assertFalse(d2.is_purebred())

 def test_bad_init(self):

 with self.assertRaises(ValueError):

 d = Dog("Fido", -10, True)

 def test_is_purebred(self):

 d = Dog("Fido", 10, True)

 d2 = Dog("Fifi", 11, False)

 self.assertTrue(d.is_purebred())

 self.assertFalse(d2.is_purebred())

 

 def test_eq(self):

 d = Dog("Fido", 10, True)

 d2 = Dog("Fifi", 11, False)

 d3 = Dog("Fifi", 11, False)

 

 self.assertTrue(d2.__eq__(d3))

 self.assertFalse(d.__eq__(d2))

 self.assertTrue(d2 == d3)

 self.assertFalse(d == d2)

 

 def test_clone(self):

 d2 = Dog("Fifi", 11, False)

 d3 = d2.clone()

 self.assertIsNot(d2,d3) # should NOT be same object!

 self.assertEqual(d2, d3) # but SHOULD be equal!

 def test_str(self):

 d = Dog("Fido", 10, True)

 d2 = Dog("Fifi", 11, False)

 msg = "Purebred: Fido 10 years"

 self.assertEqual(d.__str__(), msg)

 

 msg = "NOT Purebred: Fifi 11 years"

 self.assertEqual(d2.__str__(), msg)

def main():

 unittest.main(verbosity = 3)

main()

 

 

 

2. Equal Stacks

You may not modify the Stack class.

Write a function named equal_stacks that accepts two stacks of Dog objects as parameters and

determines if the two stacks are equal to each other. Two stacks are equal if (1) they contain the same

number of objects, and (2) the corresponding objects in each stack are identical, according to your

__eq__ method. Your function should return a Boolean.

Note: If you were unable to get your Dog class working in problem 8, you may assume we’ll use a

Stack of integers for this question.

For example, these stacks are equal...

 s1 = Stack()

 s1.push(Dog(“Fido”, 10, True))

 s1.push(Dog(“Fifi”, 11, False))

 s2 = Stack()

 s1.push(Dog(“Fido”, 10, True))

 s1.push(Dog(“Fifi”, 11, False))

... these stacks are not:

s3 = Stack()

 s1.push(Dog(“Fido”, 10, True))

 s1.push(Dog(“Fifi”, 11, False))

s4 = Stack()

 s1.push(Dog(“Fido”, 10, True))

 s1.push(Dog(“Fifi”, 5, True))

... and these stacks are not:

s3 = Stack()

 s1.push(Dog(“Fido”, 10, True))

s4 = Stack()

 s1.push(Dog(“Fido”, 10, True))

 s1.push(Dog(“Fifi”, 11, False))

 

 

3. Predicate & Filter

(a) Write a predicate function (named predicate) that takes as input a single integer. It uses the

constant MAX_VALUE given below as the basis of its test. If the integer is less than or equal to

MAX_VALUE, your predicate function should return True. Otherwise return False.

● Name: predicate

● Parameters: an integer

● Returns: True or False, depending on if the parameter is less-than-or-equal-to

MAX_VALUE, or not

MAX_VALUE = 10

(b) Write a filter function called filter_at. Your function must take a list of integers as its only

parameter and return a new list that contains the integers for which your predicate() written in

part (a) returned True. Your filter_at() function MUST use your predicate() function for

its implementation.

Example (given MAX_VALUE == 10 as before):

 x = [1, 2, 30, 4, 55, 6, 10, 20, 5, 100]

 print(filter_at(x))

Gives this output:

 [1, 2, 4, 6, 10, 5]

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme