Skip to content

Instantly share code, notes, and snippets.

@redhog
Last active August 29, 2015 14:08
Show Gist options
  • Save redhog/a452c22f9fca019b9587 to your computer and use it in GitHub Desktop.
Save redhog/a452c22f9fca019b9587 to your computer and use it in GitHub Desktop.
Test class
class Galaxy(object):
def __init__(self, size, expansionRate):
self.size = size
self.time = 0
self.expansionRate = expansionRate
def update(self):
self.time += 1
self.size += self.expansionRate
def currentSize(self):
return self.size
g1 = Galaxy(5, 10)
g2 = Galaxy(2, 3)
for x in xrange(0, 10):
g1.update()
g2.update()
print g1.currentSize()
print g2.currentSize()
class PeriodicGalaxy(Galaxy):
PI = 3.141592654
def __init__(self, size, expansionRate, offset):
Galaxy.__init__(self, size, expansionRate)
self.offset = offset
def update(self):
self.size = self.offset + sin(self.time * self.expansionRate * 2 * self.PI)
g3 = PeriodicGalaxy(3, 5)
@redhog
Copy link
Author

redhog commented Nov 7, 2014

g1 = Galaxy(5, 10)
calls
g1._ _ init _ _(5, 10)
implicitly

@redhog
Copy link
Author

redhog commented Nov 7, 2014

type(g3) == PeriodicGalaxy
isinstance(g3, PeriodicGalaxy) == True
isinstance(g3, Galaxy) == True
isinstance(g1, PeriodicGalaxy) == False
isinstance(g1, Galaxy) == True

@redhog
Copy link
Author

redhog commented Nov 7, 2014

type(PeriodicGalaxy) == type
type(type) == type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment