def testArea(self): self.assertAlmostEqual(Square(5).getArea(),5**2) self.assertAlmostEqual(Square(7.2).getArea(),(7.2)**2) self.assertAlmostEqual(Square(0.5).getArea(),(0.5)**2) self.assertAlmostEqual(Square(0.231).getArea(),(0.231)**2) self.assertAlmostEqual(Square(0).getArea(),-1) self.assertAlmostEqual(Square(-5).getArea(),-1) self.assertAlmostEqual(Square(-8.23).getArea(),-1) self.assertAlmostEqual(Square(None).getArea(),-1) self.assertAlmostEqual(Square('ok').getArea(),-1)
def testPerimeter(self): self.assertAlmostEqual(Square(5).getPerimeter(),5*4) self.assertAlmostEqual(Square(7.2).getPerimeter(),(7.2)*4) self.assertAlmostEqual(Square(0.5).getPerimeter(),(0.5)*4) self.assertAlmostEqual(Square(0.231).getPerimeter(),(0.231)*4) self.assertAlmostEqual(Square(0).getPerimeter(),-1) self.assertAlmostEqual(Square(-5).getPerimeter(),-1) self.assertAlmostEqual(Square(-8.23).getPerimeter(),-1) self.assertAlmostEqual(Square(None).getPerimeter(),-1) self.assertAlmostEqual(Square('hi').getPerimeter(),-1)
def api_play(shape): if request.method == "POST": if shape == "STAR": Star().run() if shape == "SQUARE": Square().run() return {"url": request.url}
def createShape(type): if type.lower() == 'square': return Square() elif type.lower() == 'rectangle': return Rectangle() elif type.lower() == 'circle': return Circle() else: return None
class TestArea(unittest.TestCase): def setUp(self): logger.info('setting up test') self.x = Square(3, 8) self.y = Triangle(3, 8) def test_result(self): logger.info('verifying square area') self.assertEqual(self.x.area(), 64) def test_result_type(self): logger.info('verifying triangle area') self.assertTrue(type(self.y.area()) == float) self.assertFalse(type(self.y.area()) == int) @unittest.skip("because I can") def test_meh(self): self.fail("no way hosay") def tearDown(self): logger.info('test well done, poorly written') pass
from Shapes import Square, Star, Circle, YumYum import time Star().run(6) Star().run(6) Star().run(6) Star().run(6) Circle().run() Square().run() Star().run()
#-------------------------------------------------------------------------------------------- # OOP program that is calculate Area and Perimeter of different shapes. #-------------------------------------------------------------------------------------------- from Shapes import Square, Rectangle #-------------------------------------------------------------------------------------------- if __name__ == '__main__': square = Square(5) print("Square Area :", square.getArea()) print("Square Perimeter :", square.getPerimeter()) rectangle = Rectangle(2, 3) print("Rectangle Area :", rectangle.getArea()) print("Rectangle Perimeter :", rectangle.getPerimeter()) #--------------------------------------------------------------------------------------------
def mousePressEvent(self, event): self.__clickx = event.x() self.__clicky = event.y() self.__randomLength = randint(10, 100) self.__randomWidth = randint(10, 100) triangle_orientation = randint(1, 4) colors = [Qt.magenta, Qt.blue, Qt.red, Qt.yellow, Qt.cyan, Qt.green] color_choice = colors[randint(0, 5)] shape_choice = randint(1, 7) if shape_choice == 1: newshape = Rectangle(self.__clickx - (self.__randomLength / 2), self.__clicky - (self.__randomWidth / 2), self.__randomLength, self.__randomWidth, color_choice) self.__shapes.append(newshape) if shape_choice == 2: newshape = Ellipse(self.__clickx - (self.__randomLength / 2), self.__clicky - (self.__randomWidth / 2), self.__randomLength, self.__randomWidth, color_choice) self.__shapes.append(newshape) if shape_choice == 3: newshape = Square(self.__clickx - (self.__randomLength / 2), self.__clicky - (self.__randomLength / 2), self.__randomLength, color_choice) self.__shapes.append(newshape) if shape_choice == 4: newshape = Circle(self.__clickx - (self.__randomLength / 2), self.__clicky - (self.__randomLength / 2), self.__randomLength, color_choice) self.__shapes.append(newshape) if shape_choice == 5: if triangle_orientation == 1: newshape = Triangle( (self.__clickx - (self.__randomLength / 2)), self.__clicky, self.__randomLength, color_choice, triangle_orientation) self.__shapes.append(newshape) if triangle_orientation == 2: newshape = Triangle( (self.__clickx + (self.__randomLength / 2)), self.__clicky, self.__randomLength, color_choice, triangle_orientation) self.__shapes.append(newshape) if triangle_orientation == 3: newshape = Triangle(self.__clickx, self.__clicky + (self.__randomLength / 2), self.__randomLength, color_choice, triangle_orientation) self.__shapes.append(newshape) if triangle_orientation == 4: newshape = Triangle(self.__clickx, self.__clicky - (self.__randomLength / 2), self.__randomLength, color_choice, triangle_orientation) self.__shapes.append(newshape) if shape_choice == 6: newshape = HourGlass(self.__clickx, self.__clicky + self.__randomLength, self.__randomLength, color_choice) self.__shapes.append(newshape) if shape_choice == 7: newshape = Diamond(self.__clickx, self.__clicky + self.__randomLength, self.__randomLength, color_choice) self.__shapes.append(newshape) self.update()
def testName(self): self.assertEqual(Square(2).getName(),"Square")
from firebase_admin import credentials from firebase_admin import firestore from time import sleep import threading from Shapes import Square, Star, Circle, YumYum DEVICE_NAME = 'prototype' MAX_ITERATIONS = 10 FOOD = "FOOD" SHAPE = "SHAPE" OFFER = "OFFER" ANSWER = "ANSWER" shapes = {"SQUARE":Square(), "STAR": Star(), "CIRCLE": Circle(), } # Use a service account cred = credentials.Certificate('firestore-sdk.json') firebase_admin.initialize_app(cred) db = firestore.client() doc_ref = db.collection('users').document(DEVICE_NAME) # Create an Event for notifying main thread. callback_done = threading.Event()
import asyncio from Shapes import Square, Star, Circle, YumYum from ControlServo import Buzzer #from streaming import offer DEVICE_NAME = 'prototype' MAX_ITERATIONS = 10 FOOD = "FOOD" SHAPE = "SHAPE" OFFER = "OFFER" ANSWER = "ANSWER" shapes = { "SQUARE": Square(), "STAR": Star(), "CIRCLE": Circle(), } # Use a service account cred = credentials.Certificate( '/home/pi/Documents/Laser-cat/firestore-sdk.json') firebase_admin.initialize_app(cred) db = firestore.client() doc_ref = db.collection('users').document(DEVICE_NAME) f = open("/home/pi/Documents/Laser-cat/ip.txt", "r") IP = f.read() f.close()
def setUp(self): logger.info('setting up test') self.x = Square(3, 8) self.y = Triangle(3, 8)