from Sprite import Sprite def tester(): try: cat = Sprite("Scratchy") except: print("If you are reading this it suggests that your") print("Sprite class has compiler issues") return try: if not (cat.getX()==0 and cat.getY()==0 and \ cat.getDirection()==90 and cat.getSize()==100 and\ cat.isVisible): print("Your constructor (the __init__ function) does not set to the defaults requested.") return except: print("Check spelling of your five accessor functions:") print(" getX()") print(" getY()") print(" getDirection()") print(" getSize()") print(" isVisible()") return try: for x in range(10): cat.move(10) if not cat.getX()==100: print("move() not working as expected when moving right.") return for x in range(9): cat.turnClockwise(10) if not cat.getDirection()==180: print("turnClockwise() or getDirection() not working as expected.") return for x in range(10): cat.move(10) if not cat.getY()==-100: print("move() not working as expected when moving down.") return for x in range(18): cat.turnCounterClockwise(10) if not cat.getDirection()==0: print("turnCounterClockwise() not working as expected [FIRST time].") return for x in range(10): cat.move(10) if not cat.getY()==0: print("move() not working as expected when moving up.") return for x in range(9): cat.turnCounterClockwise(10) if not cat.getDirection()==-90: print("turnCounterClockwise() not working as expected [SECOND time].") return for x in range(10): cat.move(10) if not cat.getX()==0: print("move() not working as expected when moving left.") return except: print("Check spelling of your basic movement functions:") print(" move()") print(" turnClockwise()") print(" turnCounterClockwise()") return try: cat.gotoXY(100,100) if not (cat.getX()==100 and cat.getY()==100): print("gotoXY() not working as expected.") return cat.changeX(10) if not (cat.getX()==110 and cat.getY()==100): print("changeX() not working as expected.") return cat.setX(10) if not (cat.getX()==10 and cat.getY()==100): print("setX() not working as expected.") return cat.changeY(40) if not (cat.getX()==10 and cat.getY()==140): print("changeY() not working as expected.") return cat.setY(50) if not (cat.getX()==10 and cat.getY()==50): print("setY() not working as expected.") return except: print("Check the spelling of your X/Y modifiers") print(" changeX()") print(" setX()") print(" changeY()") print(" setY()") print(" gotoXY()") return try: cat.pointInDirection(45) if not cat.getDirection()==45: print("pointInDirection() not working as expected.") cat.hide() if cat.isVisible(): print("hide() or isVisible() not working as expected.") return cat.show() if not cat.isVisible(): print("show() or isVisible() not working as expected.") return cat.changeSize(-30) if not cat.getSize()==70: print("changeSize() or getSize() not working as expected.") return cat.setSize(50) if not cat.getSize()==50: print("setSize not working as expected.") return except: print("Check the spelling of") print(" pointInDirection()") print(" hide()") print(" show()") print(" changeSize()") print(" setSize()") return try: cat.pointInDirection(200) if not cat.getDirection()==-160: print("pointInDirection(200) should produce -160") return cat.pointInDirection(-220) if not cat.getDirection()==140: print("pointInDirection(-220) should produce 140") return cat.pointInDirection(170) cat.turnClockwise(30) if not cat.getDirection()==-160: print("Clockwise turn of 30 from a start of 170 should produce -160.") return cat.turnCounterClockwise(50) if not cat.getDirection()==150: print("CounterClockwise turn of 50 from a start of -160 should produce 150.") return cat.pointInDirection(-20) cat.turnClockwise(30) if not cat.getDirection()==10: print("Clockwise turn of 30 from a start of -20 should produce 10.") return cat.turnCounterClockwise(50) if not cat.getDirection()==-40: print("CounterClockwise turn of 50 from a start of 10 should produce -40.") return cat.pointInDirection(0) if not cat.getDirection()==0: print("pointInDirection(0) should produce 0.") return for x in range(40): cat.turnClockwise(25) if not cat.getDirection()==-80: print("Spinning clockwise broke your class.") return for x in range(30): cat.turnCounterClockwise(25) if not cat.getDirection()==-110: print("Spinning counter clockwise broke your class.") return except: print("Unexpected naming/spelling error with one of:") print(" turnClockwise()") print(" turnCounterClockwise()") print(" setDirection()") print(" getDirection()") return try: cat.pointInDirection(30) cat.setX(0) cat.setY(0) cat.move(100) if abs(cat.getX()-50)>1 or abs(cat.getY()-86.6)>1: print("I don't think you are moving properly with a direction of 30") return except: print("Unexpected naming error with on of:") print(" pointInDirection()") print(" setX()") print(" setY()") print(" move()") return try: cat.pointInDirection(-20) cat.setX(0) cat.setY(0) cat.move(100) if abs(cat.getX()+34.2)>1 or abs(cat.getY()-94.4)>1: print("I don't think you are moving properly with a direction of -20") return except: print("Unexpected naming error with on of:") print(" pointInDirection()") print(" setX()") print(" setY()") print(" move()") return try: cat.pointInDirection(-100) cat.setX(0) cat.setY(0) cat.move(100) if abs(cat.getX()+98.5)>1 or abs(cat.getY()+17.4)>1: print("I don't think you are moving properly with a direction of -100") return except: print("Unexpected naming error with on of:") print(" pointInDirection()") print(" setX()") print(" setY()") print(" move()") return try: cat.pointInDirection(110) cat.setX(0) cat.setY(0) cat.move(100) if abs(cat.getX()-94)>1 or abs(cat.getY()+34.2)>1: print("I don't think you are moving properly with a direction of 110") return except: print("Unexpected error with on of:") print(" pointInDirection()") print(" setX()") print(" setY()") print(" move()") return try: direct = [0,90,180,-90,20,80,160,-80] which = ["top","right","bottom","left","top","right","bottom","left"] for x in range(4): cat.pointInDirection(direct[x]) cat.setX(0) cat.setY(0) cat.move(4000) if not (-180<=cat.getY()<=180 and -240<=cat.getX()<=240): print("You allowed the sprite to move off the "+which[x]+" edge off the screen") return except: print("Unexpected error with one of:") print(" pointInDirection()") print(" setX()") print(" setY()") print(" move()") print("If you see this I think you got it right!") tester()