Created
April 3, 2013 23:12
-
-
Save NicMcPhee/5306325 to your computer and use it in GitHub Desktop.
Unfinished solution to the word wrap kata from the 3 April 2013 coding dojo at the University of Minnesota, Morris. We got a number of good tests written and can pass several of them, but time ran out just as we were wrestling with where to put the line break in more complex situations. For the record the "customer" (me) requested that the funct…
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
import wordWrap | |
import unittest | |
import sys | |
class TestWordWrap(unittest.TestCase): | |
def setUp(self): | |
self.string = "Andrew is a pretty cool dude!" | |
def tearDown(self): | |
pass | |
def testWordWrap(self): | |
expected = "Andrew\n is a \npretty\n cool \ndude!" | |
lineLength = 6 | |
self.assertEqual(expected, wordWrap.breakUpString(lineLength, self.string)) | |
def testEmptyString(self): | |
expected = "" | |
lineLength = 2 | |
self.assertEqual(expected, wordWrap.breakUpString(lineLength, "")) | |
def testShortLine(self): | |
expected = "Bob" | |
lineLength = 612 | |
self.assertEqual(expected, wordWrap.breakUpString(lineLength, "Bob")) | |
def testSameLength(self): | |
expected = "Bob" | |
lineLength = 3 | |
self.assertEqual(expected, wordWrap.breakUpString(lineLength, "Bob")) | |
def testSimpleOverflow(self): | |
expected = "Bob\n is" | |
lineLength = 3 | |
self.assertEqual(expected, wordWrap.breakUpString(lineLength, "Bob is")) | |
def testManyBreaks(self): | |
expected = "Bob" | |
lineLength = 1 | |
self.assertEqual(expected, wordWrap.breakUpString(lineLength, "Bob")) | |
if __name__ == '__main__': | |
try: | |
unittest.main() | |
except SystemExit as inst: | |
if inst.args[0] is True: | |
raise |
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
def breakUpString(lineLength, string): | |
if lineLength >= len(string): | |
return string | |
else: | |
return string[0:lineLength] + "\n" + breakUpString(lineLength, string[lineLength:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment