-
-
Save dedan/1426868 to your computer and use it in GitHub Desktop.
sess3
This file contains 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
#!/usr/bin/env python | |
# encoding: utf-8 | |
class Life(object): | |
"""docstring for Life""" | |
def __init__(self, initial_cell_coordinates): | |
super(Life, self).__init__() | |
self.cells = set(initial_cell_coordinates) | |
for coordinate in initial_cell_coordinates: | |
self.cells.append({'x': coordinate[0], 'y': coordinate[1]}) | |
def get_bounderies(self, axis): | |
"""docstring for get_bounderies""" | |
values_on_axis = [cell[axis] for cell in self.cells] | |
return (min(values_on_axis), max(values_on_axis)) | |
def render(self): | |
for y in range(self.get_bounderies('y')): | |
for x in range(self.get_bounderies('x')): | |
def main(): | |
"""docstring for main""" | |
init_set = [(1, 0), (1, 1), (1, 2)] | |
life = Life(init_set) | |
life.render() | |
if __name__ == '__main__': | |
main() |
This file contains 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
import unittest | |
from conway import Life | |
class TestConway(unittest.TestCase): | |
def setUp(self): | |
init_set = [(1, 0), (1, 1), (1, 2)] | |
self.life = Life(init_set) | |
def testConvertCoordinatesToDictionary(self): | |
self.assertEqual(self.life.cells[0]['x'], 1) | |
self.assertEqual(self.life.cells[0]['y'], 0) | |
def testFindBoundriesSpace(self): | |
self.assertEqual((1,1), self.life.get_bounderies('x')) | |
self.assertEqual((0,2), self.life.get_bounderies('y')) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment