Commit cf2eff82 authored by Adrian Buchholz's avatar Adrian Buchholz

added oop tests

parent 58daf38a
File added
[start maze]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% G %
% GGGG %
% %
% %
% %
......
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def calculate_area(self):
return self.width * self.height
@classmethod
def new_square(cls, side_length):
return cls(side_length, side_length)
square = Rectangle.new_square(5)
print(square.calculate_area())
class Pizza:
def __init__(self, toppings):
self.toppings = toppings
@staticmethod
def validate_topping(topping):
if topping == "pineapple":
raise ValueError("No pineapples!")
else:
return True
ingredients = ["cheese", "onions", "pineapple"]
if all(Pizza.validate_topping(i) for i in ingredients):
pizza = Pizza(ingredients)
\ No newline at end of file
class Queue:
def __init__(self, contents):
self._hiddenlist = list(contents)
def push(self, value):
self._hiddenlist.insert(0, value)
def pop(self):
return self._hiddenlist.pop(-1)
def __repr__(self):
return "Queue({})".format(self._hiddenlist)
queue = Queue([1, 2, 3])
print(queue)
queue.push(0)
print(queue)
queue.pop()
print(queue)
print(queue._hiddenlist)
class Spam:
__egg = 7
def print_egg(self):
print(self.__egg)
s = Spam()
s.print_egg()
print(s._Spam__egg)
#Error because strongly private method
print(s.__egg)
\ No newline at end of file
a = 42
print(a)
b = a
print(b)
c = [a]
print(c)
#Deletes the Object so it no Longer Exists
del a
#Sets b to 100
b = 100
print(b)
#Sets the first value in the list to -1
c[0] = -1
print(c)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment