Skip to content

Commit

Permalink
split out utilities from ob.py to ob_util.py
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed Jun 21, 2017
1 parent 7eb7294 commit a66e523
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions ob/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import ob
import ob_util
11 changes: 0 additions & 11 deletions ob/ob.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ def from_ship_name(name, unscramble=True):
return addr


def nth_planet_of_star(star, n):
return n * 65536 + star


def is_syllable(set, syllable):
if not syllable or len(syllable) != 3:
return False
Expand All @@ -267,10 +263,3 @@ def is_prefix_syllable(syllable):

def is_suffix_syllable(syllable):
return is_syllable(suffix, syllable)


def generate_planets(star):
planet_index = 1
while planet_index < 65536:
yield nth_planet_of_star(star, planet_index)
planet_index += 1
8 changes: 8 additions & 0 deletions ob/ob_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def nth_planet_of_star(star, n):
return n * 65536 + star

def generate_planets(star):
planet_index = 1
while planet_index < 65536:
yield nth_planet_of_star(star, planet_index)
planet_index += 1
11 changes: 1 addition & 10 deletions ob/test_ob.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .context import ob

class MyTest(unittest.TestCase):
class ObTest(unittest.TestCase):
def test_feen(self):
self.assertEqual(ob.feen(0x10100), 0x63b30e1c)

Expand Down Expand Up @@ -60,12 +60,3 @@ def test_from_ship_name(self):
self.assertEquals(ob.from_ship_name('marzod'), 0x100)
self.assertEquals(ob.from_ship_name('doznec-marzod', unscramble=False), 0x10100)
self.assertEquals(ob.from_ship_name('wicdev-wisryt'), 0x10100)

def test_generate_planets(self):
planets = ob.generate_planets(0x100)
self.assertEquals(planets.next(), 0x10100)
self.assertEquals(planets.next(), 0x20100)

planets = ob.generate_planets(0x4141)
self.assertEquals(planets.next(), 0x14141)
self.assertEquals(planets.next(), 0x24141)
13 changes: 13 additions & 0 deletions ob/test_ob_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest

from .context import ob_util

class ObUtilTest(unittest.TestCase):
def test_generate_planets(self):
planets = ob_util.generate_planets(0x100)
self.assertEquals(planets.next(), 0x10100)
self.assertEquals(planets.next(), 0x20100)

planets = ob_util.generate_planets(0x4141)
self.assertEquals(planets.next(), 0x14141)
self.assertEquals(planets.next(), 0x24141)
4 changes: 2 additions & 2 deletions ob_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import argparse

from ob import ob
from ob import ob, ob_util


def print_addr(addr):
Expand All @@ -13,7 +13,7 @@ def print_addr(addr):


def print_all_star_planets(star):
for planet in ob.generate_planets(star):
for planet in ob_util.generate_planets(star):
print_addr(planet)


Expand Down

0 comments on commit a66e523

Please sign in to comment.