import unittest import inspect ### OOP #1 ### The file name should be renamed to your Student ID (00XXXXXXX_hw4.py) ### Each question in section 1 is worth 10 points. ### Each question in section 2 is...

1 answer below »
NO pdf or Doc form of the assignment


import unittest import inspect ### OOP #1 ### The file name should be renamed to your Student ID (00XXXXXXX_hw4.py) ### Each question in section 1 is worth 10 points. ### Each question in section 2 is worth 20 points. ### Your programs should pass the provided test cases. ### When you want to test your program, uncomment the appropriate test case from bottom, run the program. ### Depending on the test results, modify the code or move to the next question. ### The questions are separate, and the earlier results do not affect your ability to complete other question. ### Do not modify the structure of the code. ### Start of HW4 # Classes class Test: def __init__(self): self.some_value = 42 def change_value(self, new_value): self.some_value = new_value def add_to_value(self, numb): return numb + self.some_value class Test1: def __init__(self, arg): self.some_value = 42 + arg # Q1A # Goal: # Call the constructor # Inputs: # None # Outputs: # An object of type Test. def q1a(): return None # Q1B # Goal: # Construct an object of type Test and return its some_value property # Inputs: # None # Outputs: # A number def q1b(): return 0 # Q1C # Goal: # Call the add_to_value function with the provided argument and return the value # Inputs: # numb is a number # Outputs: # A number def q1c(numb): return 0 # Q1D # Goal: # Construct an object of type of Test1 using the provided input value. # Inputs: # numb is a number # Outputs: # Return an object of type Test1 def q1d(numb): return None # Q2A # Goal: # Return a class which has a constructor that accepts an argument named 'arg' and sets the internal object property 'green' on self to the provided value. # Inputs: # None # Outputs: # Return an object of type Test1 # class Myclass: # .... # x = Myclass('orange') # x.green == 'orange' <- this should be true def q2a(): class a: pass return a # q2b # goal: # return a class which has a constructor that sets the object property 'counter' to 12 # inputs: # none # outputs: # return a class with "increment" and "decrement" methods, each of which add or remove one from 'counter' respectively. def q2b(): class a: pass return a # test # tells you which test case the program has failed in terminal. # these are examples of test cases provided for you to test your program during the homework. # all test cases should pass. # uncomment the class when you want to test your program! class testquestion1a(unittest.testcase): def test_one(self): self.assertisinstance(q1a(), test) class testquestion1b(unittest.testcase): def test_one(self): self.assertequal(q1b(), 42) class testquestion1c(unittest.testcase): def test_one(self): self.assertequal(q1c(12), 54) def test_two(self): self.assertequal(q1c(42), 84) class testquestion1d(unittest.testcase): def test_one(self): self.assertisinstance(q1d(1), test1) self.assertequal(q1d(12).some_value, 54) class testquestion2a(unittest.testcase): def test_one(self): cls = q2a() assert '__init__' in dir(cls), 'class has no constructor' assert 'arg' in inspect.getfullargspec(cls.__init__).args, 'arg should be an argument for the constructor' assert 'self' in inspect.getfullargspec(cls.__init__).args, 'self should be an argument for the constructor' assert len(inspect.getfullargspec(cls.__init__).args) == 2, 'the constructor should have exactly two arguments' instance = cls(5) assert 'green' in dir(instance), 'green is not a property of the object' self.assertequal(instance.green, 5) class testquestion2b(unittest.testcase): def test_one(self): cls = q2b() assert '__init__' in dir(cls), 'class has no constructor' assert 'self' in inspect.getfullargspec(cls.__init__).args, 'self should be an argument for the constructor' assert len(inspect.getfullargspec(cls.__init__).args) == 1, 'the constructor should have exactly one argument' instance = cls() assert 'counter' in dir(instance), 'counter is not a property of the object' self.assertequal(instance.counter, 12) assert 'increment' in dir(instance), 'the increment method does not exist' assert 'decrement' in dir(instance), 'the decrement method does not exist' instance.increment() assert instance.counter == 13, 'using the increment method should result in `counter` increasing by one' instance.decrement() instance.decrement() assert instance.counter == 11, 'using the decrement method should result in `counter` decreasing by one' if __name__ == '__main__': unittest.main() this="" should="" be="" true="" def="" q2a():="" class="" a:="" pass="" return="" a="" #="" q2b="" #="" goal:="" #="" return="" a="" class="" which="" has="" a="" constructor="" that="" sets="" the="" object="" property="" 'counter'="" to="" 12="" #="" inputs:="" #="" none="" #="" outputs:="" #="" return="" a="" class="" with="" "increment"="" and="" "decrement"="" methods,="" each="" of="" which="" add="" or="" remove="" one="" from="" 'counter'="" respectively.="" def="" q2b():="" class="" a:="" pass="" return="" a="" #="" test="" #="" tells="" you="" which="" test="" case="" the="" program="" has="" failed="" in="" terminal.="" #="" these="" are="" examples="" of="" test="" cases="" provided="" for="" you="" to="" test="" your="" program="" during="" the="" homework.="" #="" all="" test="" cases="" should="" pass.="" #="" uncomment="" the="" class="" when="" you="" want="" to="" test="" your="" program!="" class="" testquestion1a(unittest.testcase):="" def="" test_one(self):="" self.assertisinstance(q1a(),="" test)="" class="" testquestion1b(unittest.testcase):="" def="" test_one(self):="" self.assertequal(q1b(),="" 42)="" class="" testquestion1c(unittest.testcase):="" def="" test_one(self):="" self.assertequal(q1c(12),="" 54)="" def="" test_two(self):="" self.assertequal(q1c(42),="" 84)="" class="" testquestion1d(unittest.testcase):="" def="" test_one(self):="" self.assertisinstance(q1d(1),="" test1)="" self.assertequal(q1d(12).some_value,="" 54)="" class="" testquestion2a(unittest.testcase):="" def="" test_one(self):="" cls="q2a()" assert="" '__init__'="" in="" dir(cls),="" 'class="" has="" no="" constructor'="" assert="" 'arg'="" in="" inspect.getfullargspec(cls.__init__).args,="" 'arg="" should="" be="" an="" argument="" for="" the="" constructor'="" assert="" 'self'="" in="" inspect.getfullargspec(cls.__init__).args,="" 'self="" should="" be="" an="" argument="" for="" the="" constructor'="" assert="" len(inspect.getfullargspec(cls.__init__).args)="=" 2,="" 'the="" constructor="" should="" have="" exactly="" two="" arguments'="" instance="cls(5)" assert="" 'green'="" in="" dir(instance),="" 'green="" is="" not="" a="" property="" of="" the="" object'="" self.assertequal(instance.green,="" 5)="" class="" testquestion2b(unittest.testcase):="" def="" test_one(self):="" cls="q2b()" assert="" '__init__'="" in="" dir(cls),="" 'class="" has="" no="" constructor'="" assert="" 'self'="" in="" inspect.getfullargspec(cls.__init__).args,="" 'self="" should="" be="" an="" argument="" for="" the="" constructor'="" assert="" len(inspect.getfullargspec(cls.__init__).args)="=" 1,="" 'the="" constructor="" should="" have="" exactly="" one="" argument'="" instance="cls()" assert="" 'counter'="" in="" dir(instance),="" 'counter="" is="" not="" a="" property="" of="" the="" object'="" self.assertequal(instance.counter,="" 12)="" assert="" 'increment'="" in="" dir(instance),="" 'the="" increment="" method="" does="" not="" exist'="" assert="" 'decrement'="" in="" dir(instance),="" 'the="" decrement="" method="" does="" not="" exist'="" instance.increment()="" assert="" instance.counter="=" 13,="" 'using="" the="" increment="" method="" should="" result="" in="" `counter`="" increasing="" by="" one'="" instance.decrement()="" instance.decrement()="" assert="" instance.counter="=" 11,="" 'using="" the="" decrement="" method="" should="" result="" in="" `counter`="" decreasing="" by="" one'="" if="" __name__="=" '__main__':="">
Answered Same DayJun 20, 2021

Answer To: import unittest import inspect ### OOP #1 ### The file name should be renamed to your Student ID...

Pratap answered on Jun 21 2021
147 Votes
import unittest
import inspect
### OOP #1
### The file name should be renamed to your Student ID (00XXXXXXX_hw4.py)
### Each question in section 1 is wor
th 10 points.
### Each question in section 2 is worth 20 points.
### Your programs should pass the provided test cases.
### When you want to test your program, uncomment the appropriate test case from bottom, run the program.
### Depending on the test results, modify the code or move to the next question.
### The questions are separate, and the earlier results do not affect your ability to complete other question.
### Do not modify the structure of the code.
### Start of HW4
# Classes
class Test:
def __init__(self):
self.some_value = 42
def change_value(self, new_value):
self.some_value = new_value
def add_to_value(self, numb):
return numb + self.some_value
class Test1:
def __init__(self, arg):
self.some_value = 42 + arg
# Q1A
# Goal:
# Call the constructor
# Inputs:
# None
# Outputs:
# An object of type Test.
def q1a():
return Test()
# Q1B
# Goal:
# Construct an object of type Test and return its some_value property
# Inputs:
# None
# Outputs:
# A number
def q1b():
test = Test()
return test.some_value
# Q1C
# Goal:
# Call the add_to_value function with the provided argument and return the value
# Inputs:
# numb is a number
# Outputs:
# A number
def q1c(numb):
test = Test()
return test.add_to_value(numb=numb)
# Q1D
# Goal:
# Construct an object of type of Test1 using...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here