Last active
August 29, 2015 14:08
-
-
Save redhog/a452c22f9fca019b9587 to your computer and use it in GitHub Desktop.
Test class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
type(g3) == PeriodicGalaxy
isinstance(g3, PeriodicGalaxy) == True
isinstance(g3, Galaxy) == True
isinstance(g1, PeriodicGalaxy) == False
isinstance(g1, Galaxy) == True
type(PeriodicGalaxy) == type
type(type) == type
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
g1 = Galaxy(5, 10)
calls
g1._ _ init _ _(5, 10)
implicitly