you wouldn't believe me if I told you

This commit is contained in:
Mark Pilgrim
2009-06-05 23:39:50 -04:00
parent cbdb346531
commit 654b102d74
64 changed files with 724 additions and 764 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
"""Find solutions to alphametic equations.
'''Find solutions to alphametic equations.
>>> alphametics.solve('SEND + MORE == MONEY')
'9567 + 1085 == 10652'
"""
'''
import re
import itertools
+15 -15
View File
@@ -3,34 +3,34 @@ import unittest
class KnownValues(unittest.TestCase):
def test_out(self):
"""TO + GO == OUT"""
self.assertEqual(solve("TO + GO == OUT"), "21 + 81 == 102")
'''TO + GO == OUT'''
self.assertEqual(solve('TO + GO == OUT'), '21 + 81 == 102')
def test_too(self):
"""I + DID == TOO"""
self.assertEqual(solve("I + DID == TOO"), "9 + 191 == 200")
'''I + DID == TOO'''
self.assertEqual(solve('I + DID == TOO'), '9 + 191 == 200')
def test_mom(self):
"""AS + A == MOM"""
self.assertEqual(solve("AS + A == MOM"), "92 + 9 == 101")
'''AS + A == MOM'''
self.assertEqual(solve('AS + A == MOM'), '92 + 9 == 101')
def test_best(self):
"""HES + THE == BEST"""
self.assertEqual(solve("HES + THE == BEST"), "426 + 842 == 1268")
'''HES + THE == BEST'''
self.assertEqual(solve('HES + THE == BEST'), '426 + 842 == 1268')
def test_late(self):
"""NO + NO + TOO == LATE"""
self.assertEqual(solve("NO + NO + TOO == LATE"), "74 + 74 + 944 == 1092")
'''NO + NO + TOO == LATE'''
self.assertEqual(solve('NO + NO + TOO == LATE'), '74 + 74 + 944 == 1092')
def test_onze(self):
"""UN + UN + NEUF == ONZE"""
self.assertEqual(solve("UN + UN + NEUF == ONZE"), "81 + 81 + 1987 == 2149")
'''UN + UN + NEUF == ONZE'''
self.assertEqual(solve('UN + UN + NEUF == ONZE'), '81 + 81 + 1987 == 2149')
def test_deux(self):
"""UN + DEUX + DEUX + DEUX + DEUX == NEUF"""
self.assertEqual(solve("UN + DEUX + DEUX + DEUX + DEUX == NEUF"), "25 + 1326 + 1326 + 1326 + 1326 == 5329")
'''UN + DEUX + DEUX + DEUX + DEUX == NEUF'''
self.assertEqual(solve('UN + DEUX + DEUX + DEUX + DEUX == NEUF'), '25 + 1326 + 1326 + 1326 + 1326 == 5329')
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+24 -24
View File
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<?xml version='1.0' encoding='utf-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xml:lang='en'>
<title>dive into &hellip;</title>
<subtitle>currently between addictions</subtitle>
<id>tag:diveintomark.org,2001-07-29:/</id>
<updated>2009-03-27T21:56:07Z</updated>
<link rel="alternate" type="text/html" href="http://diveintomark.org/"/>
<link rel='alternate' type='text/html' href='http://diveintomark.org/'/>
<entry>
<author>
<name>Mark</name>
<uri>http://diveintomark.org/</uri>
</author>
<title>Dive into history, 2009 edition</title>
<link rel="alternate" type="text/html"
href="http://diveintomark.org/archives/2009/03/27/dive-into-history-2009-edition"/>
<link rel='alternate' type='text/html'
href='http://diveintomark.org/archives/2009/03/27/dive-into-history-2009-edition'/>
<id>tag:diveintomark.org,2009-03-27:/archives/20090327172042</id>
<updated>2009-03-27T21:56:07Z</updated>
<published>2009-03-27T17:20:42Z</published>
<category scheme="http://diveintomark.org" term="diveintopython"/>
<category scheme="http://diveintomark.org" term="docbook"/>
<category scheme="http://diveintomark.org" term="html"/>
<summary type="html">Putting an entire chapter on one page sounds
<category scheme='http://diveintomark.org' term='diveintopython'/>
<category scheme='http://diveintomark.org' term='docbook'/>
<category scheme='http://diveintomark.org' term='html'/>
<summary type='html'>Putting an entire chapter on one page sounds
bloated, but consider this &amp;mdash; my longest chapter so far
would be 75 printed pages, and it loads in under 5 seconds&amp;hellip;
On dialup.</summary>
@@ -30,13 +30,13 @@
<uri>http://diveintomark.org/</uri>
</author>
<title>Accessibility is a harsh mistress</title>
<link rel="alternate" type="text/html"
href="http://diveintomark.org/archives/2009/03/21/accessibility-is-a-harsh-mistress"/>
<link rel='alternate' type='text/html'
href='http://diveintomark.org/archives/2009/03/21/accessibility-is-a-harsh-mistress'/>
<id>tag:diveintomark.org,2009-03-21:/archives/20090321200928</id>
<updated>2009-03-22T01:05:37Z</updated>
<published>2009-03-21T20:09:28Z</published>
<category scheme="http://diveintomark.org" term="accessibility"/>
<summary type="html">The accessibility orthodoxy does not permit people to
<category scheme='http://diveintomark.org' term='accessibility'/>
<summary type='html'>The accessibility orthodoxy does not permit people to
question the value of features that are rarely useful and rarely used.</summary>
</entry>
<entry>
@@ -44,20 +44,20 @@
<name>Mark</name>
</author>
<title>A gentle introduction to video encoding, part 1: container formats</title>
<link rel="alternate" type="text/html"
href="http://diveintomark.org/archives/2008/12/18/give-part-1-container-formats"/>
<link rel='alternate' type='text/html'
href='http://diveintomark.org/archives/2008/12/18/give-part-1-container-formats'/>
<id>tag:diveintomark.org,2008-12-18:/archives/20081218155422</id>
<updated>2009-01-11T19:39:22Z</updated>
<published>2008-12-18T15:54:22Z</published>
<category scheme="http://diveintomark.org" term="asf"/>
<category scheme="http://diveintomark.org" term="avi"/>
<category scheme="http://diveintomark.org" term="encoding"/>
<category scheme="http://diveintomark.org" term="flv"/>
<category scheme="http://diveintomark.org" term="GIVE"/>
<category scheme="http://diveintomark.org" term="mp4"/>
<category scheme="http://diveintomark.org" term="ogg"/>
<category scheme="http://diveintomark.org" term="video"/>
<summary type="html">These notes will eventually become part of a
<category scheme='http://diveintomark.org' term='asf'/>
<category scheme='http://diveintomark.org' term='avi'/>
<category scheme='http://diveintomark.org' term='encoding'/>
<category scheme='http://diveintomark.org' term='flv'/>
<category scheme='http://diveintomark.org' term='GIVE'/>
<category scheme='http://diveintomark.org' term='mp4'/>
<category scheme='http://diveintomark.org' term='ogg'/>
<category scheme='http://diveintomark.org' term='video'/>
<summary type='html'>These notes will eventually become part of a
tech talk on video encoding.</summary>
</entry>
</feed>
+24 -24
View File
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<ns0:feed xmlns:ns0="http://www.w3.org/2005/Atom" xml:lang="en">
<?xml version='1.0' encoding='utf-8'?>
<ns0:feed xmlns:ns0='http://www.w3.org/2005/Atom' xml:lang='en'>
<ns0:title>dive into mark</ns0:title>
<ns0:subtitle>currently between addictions</ns0:subtitle>
<ns0:id>tag:diveintomark.org,2001-07-29:/</ns0:id>
<ns0:updated>2009-03-27T21:56:07Z</ns0:updated>
<ns0:link rel="alternate" type="text/html" href="http://diveintomark.org/"/>
<ns0:link rel='alternate' type='text/html' href='http://diveintomark.org/'/>
<ns0:entry>
<ns0:author>
<ns0:name>Mark</ns0:name>
<ns0:uri>http://diveintomark.org/</ns0:uri>
</ns0:author>
<ns0:title>Dive into history, 2009 edition</ns0:title>
<ns0:link rel="alternate" type="text/html"
href="http://diveintomark.org/archives/2009/03/27/dive-into-history-2009-edition"/>
<ns0:link rel='alternate' type='text/html'
href='http://diveintomark.org/archives/2009/03/27/dive-into-history-2009-edition'/>
<ns0:id>tag:diveintomark.org,2009-03-27:/archives/20090327172042</ns0:id>
<ns0:updated>2009-03-27T21:56:07Z</ns0:updated>
<ns0:published>2009-03-27T17:20:42Z</ns0:published>
<ns0:category scheme="http://diveintomark.org" term="diveintopython"/>
<ns0:category scheme="http://diveintomark.org" term="docbook"/>
<ns0:category scheme="http://diveintomark.org" term="html"/>
<ns0:summary type="html">Putting an entire chapter on one page sounds
<ns0:category scheme='http://diveintomark.org' term='diveintopython'/>
<ns0:category scheme='http://diveintomark.org' term='docbook'/>
<ns0:category scheme='http://diveintomark.org' term='html'/>
<ns0:summary type='html'>Putting an entire chapter on one page sounds
bloated, but consider this &amp;mdash; my longest chapter so far
would be 75 printed pages, and it loads in under 5 seconds&amp;hellip;
On dialup.</ns0:summary>
@@ -30,13 +30,13 @@
<ns0:uri>http://diveintomark.org/</ns0:uri>
</ns0:author>
<ns0:title>Accessibility is a harsh mistress</ns0:title>
<ns0:link rel="alternate" type="text/html"
href="http://diveintomark.org/archives/2009/03/21/accessibility-is-a-harsh-mistress"/>
<ns0:link rel='alternate' type='text/html'
href='http://diveintomark.org/archives/2009/03/21/accessibility-is-a-harsh-mistress'/>
<ns0:id>tag:diveintomark.org,2009-03-21:/archives/20090321200928</ns0:id>
<ns0:updated>2009-03-22T01:05:37Z</ns0:updated>
<ns0:published>2009-03-21T20:09:28Z</ns0:published>
<ns0:category scheme="http://diveintomark.org" term="accessibility"/>
<ns0:summary type="html">The accessibility orthodoxy does not permit people to
<ns0:category scheme='http://diveintomark.org' term='accessibility'/>
<ns0:summary type='html'>The accessibility orthodoxy does not permit people to
question the value of features that are rarely useful and rarely used.</ns0:summary>
</ns0:entry>
<ns0:entry>
@@ -44,20 +44,20 @@
<ns0:name>Mark</ns0:name>
</ns0:author>
<ns0:title>A gentle introduction to video encoding, part 1: container formats</ns0:title>
<ns0:link rel="alternate" type="text/html"
href="http://diveintomark.org/archives/2008/12/18/give-part-1-container-formats"/>
<ns0:link rel='alternate' type='text/html'
href='http://diveintomark.org/archives/2008/12/18/give-part-1-container-formats'/>
<ns0:id>tag:diveintomark.org,2008-12-18:/archives/20081218155422</ns0:id>
<ns0:updated>2009-01-11T19:39:22Z</ns0:updated>
<ns0:published>2008-12-18T15:54:22Z</ns0:published>
<ns0:category scheme="http://diveintomark.org" term="asf"/>
<ns0:category scheme="http://diveintomark.org" term="avi"/>
<ns0:category scheme="http://diveintomark.org" term="encoding"/>
<ns0:category scheme="http://diveintomark.org" term="flv"/>
<ns0:category scheme="http://diveintomark.org" term="GIVE"/>
<ns0:category scheme="http://diveintomark.org" term="mp4"/>
<ns0:category scheme="http://diveintomark.org" term="ogg"/>
<ns0:category scheme="http://diveintomark.org" term="video"/>
<ns0:summary type="html">These notes will eventually become part of a
<ns0:category scheme='http://diveintomark.org' term='asf'/>
<ns0:category scheme='http://diveintomark.org' term='avi'/>
<ns0:category scheme='http://diveintomark.org' term='encoding'/>
<ns0:category scheme='http://diveintomark.org' term='flv'/>
<ns0:category scheme='http://diveintomark.org' term='GIVE'/>
<ns0:category scheme='http://diveintomark.org' term='mp4'/>
<ns0:category scheme='http://diveintomark.org' term='ogg'/>
<ns0:category scheme='http://diveintomark.org' term='video'/>
<ns0:summary type='html'>These notes will eventually become part of a
tech talk on video encoding.</ns0:summary>
</ns0:entry>
</ns0:feed>
+24 -24
View File
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<?xml version='1.0' encoding='utf-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xml:lang='en'>
<title>dive into mark</title>
<subtitle>currently between addictions</subtitle>
<id>tag:diveintomark.org,2001-07-29:/</id>
<updated>2009-03-27T21:56:07Z</updated>
<link rel="alternate" type="text/html" href="http://diveintomark.org/"/>
<link rel='alternate' type='text/html' href='http://diveintomark.org/'/>
<entry>
<author>
<name>Mark</name>
<uri>http://diveintomark.org/</uri>
</author>
<title>Dive into history, 2009 edition</title>
<link rel="alternate" type="text/html"
href="http://diveintomark.org/archives/2009/03/27/dive-into-history-2009-edition"/>
<link rel='alternate' type='text/html'
href='http://diveintomark.org/archives/2009/03/27/dive-into-history-2009-edition'/>
<id>tag:diveintomark.org,2009-03-27:/archives/20090327172042</id>
<updated>2009-03-27T21:56:07Z</updated>
<published>2009-03-27T17:20:42Z</published>
<category scheme="http://diveintomark.org" term="diveintopython"/>
<category scheme="http://diveintomark.org" term="docbook"/>
<category scheme="http://diveintomark.org" term="html"/>
<summary type="html">Putting an entire chapter on one page sounds
<category scheme='http://diveintomark.org' term='diveintopython'/>
<category scheme='http://diveintomark.org' term='docbook'/>
<category scheme='http://diveintomark.org' term='html'/>
<summary type='html'>Putting an entire chapter on one page sounds
bloated, but consider this &amp;mdash; my longest chapter so far
would be 75 printed pages, and it loads in under 5 seconds&amp;hellip;
On dialup.</summary>
@@ -30,13 +30,13 @@
<uri>http://diveintomark.org/</uri>
</author>
<title>Accessibility is a harsh mistress</title>
<link rel="alternate" type="text/html"
href="http://diveintomark.org/archives/2009/03/21/accessibility-is-a-harsh-mistress"/>
<link rel='alternate' type='text/html'
href='http://diveintomark.org/archives/2009/03/21/accessibility-is-a-harsh-mistress'/>
<id>tag:diveintomark.org,2009-03-21:/archives/20090321200928</id>
<updated>2009-03-22T01:05:37Z</updated>
<published>2009-03-21T20:09:28Z</published>
<category scheme="http://diveintomark.org" term="accessibility"/>
<summary type="html">The accessibility orthodoxy does not permit people to
<category scheme='http://diveintomark.org' term='accessibility'/>
<summary type='html'>The accessibility orthodoxy does not permit people to
question the value of features that are rarely useful and rarely used.</summary>
</entry>
<entry>
@@ -44,20 +44,20 @@
<name>Mark</name>
</author>
<title>A gentle introduction to video encoding, part 1: container formats</title>
<link rel="alternate" type="text/html"
href="http://diveintomark.org/archives/2008/12/18/give-part-1-container-formats"/>
<link rel='alternate' type='text/html'
href='http://diveintomark.org/archives/2008/12/18/give-part-1-container-formats'/>
<id>tag:diveintomark.org,2008-12-18:/archives/20081218155422</id>
<updated>2009-01-11T19:39:22Z</updated>
<published>2008-12-18T15:54:22Z</published>
<category scheme="http://diveintomark.org" term="asf"/>
<category scheme="http://diveintomark.org" term="avi"/>
<category scheme="http://diveintomark.org" term="encoding"/>
<category scheme="http://diveintomark.org" term="flv"/>
<category scheme="http://diveintomark.org" term="GIVE"/>
<category scheme="http://diveintomark.org" term="mp4"/>
<category scheme="http://diveintomark.org" term="ogg"/>
<category scheme="http://diveintomark.org" term="video"/>
<summary type="html">These notes will eventually become part of a
<category scheme='http://diveintomark.org' term='asf'/>
<category scheme='http://diveintomark.org' term='avi'/>
<category scheme='http://diveintomark.org' term='encoding'/>
<category scheme='http://diveintomark.org' term='flv'/>
<category scheme='http://diveintomark.org' term='GIVE'/>
<category scheme='http://diveintomark.org' term='mp4'/>
<category scheme='http://diveintomark.org' term='ogg'/>
<category scheme='http://diveintomark.org' term='video'/>
<summary type='html'>These notes will eventually become part of a
tech talk on video encoding.</summary>
</entry>
</feed>
+1 -1
View File
@@ -1,4 +1,4 @@
"""Fibonacci generator"""
'''Fibonacci generator'''
def fib(max):
a, b = 0, 1
+2 -2
View File
@@ -1,7 +1,7 @@
"""Fibonacci iterator"""
'''Fibonacci iterator'''
class Fib:
"""iterator that yields numbers in the Fibonacci sequence"""
'''iterator that yields numbers in the Fibonacci sequence'''
def __init__(self, max):
self.max = max
+6 -6
View File
@@ -1,4 +1,4 @@
"""Convert file sizes to human-readable form.
'''Convert file sizes to human-readable form.
Available functions:
approximate_size(size, a_kilobyte_is_1024_bytes)
@@ -10,13 +10,13 @@ Examples:
>>> approximate_size(1000, False)
'1.0 KB'
"""
'''
SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}
def approximate_size(size, a_kilobyte_is_1024_bytes=True):
"""Convert a file size to human-readable form.
'''Convert a file size to human-readable form.
Keyword arguments:
size -- file size in bytes
@@ -25,7 +25,7 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True):
Returns: string
"""
'''
if size < 0:
raise ValueError('number must be non-negative')
@@ -33,11 +33,11 @@ def approximate_size(size, a_kilobyte_is_1024_bytes=True):
for suffix in SUFFIXES[multiple]:
size /= multiple
if size < multiple:
return "{0:.1f} {1}".format(size, suffix)
return '{0:.1f} {1}'.format(size, suffix)
raise ValueError('number too large')
if __name__ == "__main__":
if __name__ == '__main__':
print(approximate_size(1000000000000, False))
print(approximate_size(1000000000000))
+2 -2
View File
@@ -1,9 +1,9 @@
"""Pluralize English nouns (stage 1)
'''Pluralize English nouns (stage 1)
Command line usage:
$ python3 plural.py noun
nouns
"""
'''
import re
+2 -2
View File
@@ -1,9 +1,9 @@
"""Pluralize English nouns (stage 2)
'''Pluralize English nouns (stage 2)
Command line usage:
$ python plural2.py noun
nouns
"""
'''
import re
+2 -2
View File
@@ -1,9 +1,9 @@
"""Pluralize English nouns (stage 3)
'''Pluralize English nouns (stage 3)
Command line usage:
$ python plural3.py noun
nouns
"""
'''
import re
+2 -2
View File
@@ -1,9 +1,9 @@
"""Pluralize English nouns (stage 4)
'''Pluralize English nouns (stage 4)
Command line usage:
$ python plural4.py noun
nouns
"""
'''
import re
+2 -2
View File
@@ -1,9 +1,9 @@
"""Pluralize English nouns (stage 5)
'''Pluralize English nouns (stage 5)
Command line usage:
$ python plural5.py noun
nouns
"""
'''
import re
+2 -2
View File
@@ -1,9 +1,9 @@
"""Pluralize English nouns (stage 6)
'''Pluralize English nouns (stage 6)
Command line usage:
$ python plural6.py noun
nouns
"""
'''
import re
+6 -6
View File
@@ -1,11 +1,11 @@
"""Unit test for plural1.py"""
'''Unit test for plural1.py'''
import plural1
import unittest
class KnownValues(unittest.TestCase):
def test_sxz(self):
"words ending in S, X, and Z"
'words ending in S, X, and Z'
nouns = {
'bass': 'basses',
'bus': 'buses',
@@ -21,7 +21,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural1.plural(singular), plural)
def test_h(self):
"words ending in H"
'words ending in H'
nouns = {
'coach': 'coaches',
'glitch': 'glitches',
@@ -34,7 +34,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural1.plural(singular), plural)
def test_y(self):
"words ending in Y"
'words ending in Y'
nouns = {
'utility': 'utilities',
'vacancy': 'vacancies',
@@ -45,7 +45,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural1.plural(singular), plural)
def test_default(self):
"unexceptional words"
'unexceptional words'
nouns = {
'papaya': 'papayas',
'whip': 'whips',
@@ -54,7 +54,7 @@ class KnownValues(unittest.TestCase):
for singular, plural in nouns.items():
self.assertEqual(plural1.plural(singular), plural)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+6 -6
View File
@@ -1,11 +1,11 @@
"""Unit test for plural2.py"""
'''Unit test for plural2.py'''
import plural2
import unittest
class KnownValues(unittest.TestCase):
def test_sxz(self):
"words ending in S, X, and Z"
'words ending in S, X, and Z'
nouns = {
'bass': 'basses',
'bus': 'buses',
@@ -21,7 +21,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural2.plural(singular), plural)
def test_h(self):
"words ending in H"
'words ending in H'
nouns = {
'coach': 'coaches',
'glitch': 'glitches',
@@ -34,7 +34,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural2.plural(singular), plural)
def test_y(self):
"words ending in Y"
'words ending in Y'
nouns = {
'utility': 'utilities',
'vacancy': 'vacancies',
@@ -45,7 +45,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural2.plural(singular), plural)
def test_default(self):
"unexceptional words"
'unexceptional words'
nouns = {
'papaya': 'papayas',
'whip': 'whips',
@@ -54,7 +54,7 @@ class KnownValues(unittest.TestCase):
for singular, plural in nouns.items():
self.assertEqual(plural2.plural(singular), plural)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+6 -6
View File
@@ -1,11 +1,11 @@
"""Unit test for plural1.py"""
'''Unit test for plural1.py'''
import plural3
import unittest
class KnownValues(unittest.TestCase):
def test_sxz(self):
"words ending in S, X, and Z"
'words ending in S, X, and Z'
nouns = {
'bass': 'basses',
'bus': 'buses',
@@ -21,7 +21,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural3.plural(singular), plural)
def test_h(self):
"words ending in H"
'words ending in H'
nouns = {
'coach': 'coaches',
'glitch': 'glitches',
@@ -34,7 +34,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural3.plural(singular), plural)
def test_y(self):
"words ending in Y"
'words ending in Y'
nouns = {
'utility': 'utilities',
'vacancy': 'vacancies',
@@ -45,7 +45,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural3.plural(singular), plural)
def test_default(self):
"unexceptional words"
'unexceptional words'
nouns = {
'papaya': 'papayas',
'whip': 'whips',
@@ -54,7 +54,7 @@ class KnownValues(unittest.TestCase):
for singular, plural in nouns.items():
self.assertEqual(plural3.plural(singular), plural)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+6 -6
View File
@@ -1,11 +1,11 @@
"""Unit test for plural1.py"""
'''Unit test for plural1.py'''
import plural4
import unittest
class KnownValues(unittest.TestCase):
def test_sxz(self):
"words ending in S, X, and Z"
'words ending in S, X, and Z'
nouns = {
'bass': 'basses',
'bus': 'buses',
@@ -21,7 +21,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural4.plural(singular), plural)
def test_h(self):
"words ending in H"
'words ending in H'
nouns = {
'coach': 'coaches',
'glitch': 'glitches',
@@ -34,7 +34,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural4.plural(singular), plural)
def test_y(self):
"words ending in Y"
'words ending in Y'
nouns = {
'utility': 'utilities',
'vacancy': 'vacancies',
@@ -45,7 +45,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural4.plural(singular), plural)
def test_default(self):
"unexceptional words"
'unexceptional words'
nouns = {
'papaya': 'papayas',
'whip': 'whips',
@@ -54,7 +54,7 @@ class KnownValues(unittest.TestCase):
for singular, plural in nouns.items():
self.assertEqual(plural4.plural(singular), plural)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+6 -9
View File
@@ -1,11 +1,11 @@
"""Unit test for plural5.py"""
'''Unit test for plural5.py'''
import plural5
import unittest
class KnownValues(unittest.TestCase):
def test_sxz(self):
"words ending in S, X, and Z"
'words ending in S, X, and Z'
nouns = {
'bass': 'basses',
'bus': 'buses',
@@ -21,7 +21,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural5.plural(singular), plural)
def test_h(self):
"words ending in H"
'words ending in H'
nouns = {
'coach': 'coaches',
'glitch': 'glitches',
@@ -34,7 +34,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural5.plural(singular), plural)
def test_y(self):
"words ending in Y"
'words ending in Y'
nouns = {
'utility': 'utilities',
'vacancy': 'vacancies',
@@ -45,7 +45,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural5.plural(singular), plural)
def test_default(self):
"unexceptional words"
'unexceptional words'
nouns = {
'papaya': 'papayas',
'whip': 'whips',
@@ -54,10 +54,7 @@ class KnownValues(unittest.TestCase):
for singular, plural in nouns.items():
self.assertEqual(plural5.plural(singular), plural)
if __name__ == "__main__":
unittest.main()
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+17 -20
View File
@@ -1,11 +1,11 @@
"""Unit test for plural6.py"""
'''Unit test for plural6.py'''
import plural6
import unittest
class KnownValues(unittest.TestCase):
def test_sxz(self):
"words ending in S, X, and Z"
'words ending in S, X, and Z'
nouns = {
'bass': 'basses',
'bus': 'buses',
@@ -21,7 +21,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_h(self):
"words ending in H"
'words ending in H'
nouns = {
'coach': 'coaches',
'glitch': 'glitches',
@@ -34,7 +34,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_y(self):
"words ending in Y"
'words ending in Y'
nouns = {
'utility': 'utilities',
'vacancy': 'vacancies',
@@ -45,7 +45,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_ouce(self):
"words ending in OUSE"
'words ending in OUSE'
nouns = {
'mouse': 'mice',
'louse': 'lice'
@@ -54,7 +54,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_child(self):
"special case: child"
'special case: child'
nouns = {
'child': 'children'
}
@@ -62,7 +62,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_oot(self):
"special case: foot"
'special case: foot'
nouns = {
'foot': 'feet'
}
@@ -70,7 +70,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_ooth(self):
"words ending in OOTH"
'words ending in OOTH'
nouns = {
'booth': 'booths',
'tooth': 'teeth'
@@ -79,7 +79,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_f_ves(self):
"words ending in F that become VES"
'words ending in F that become VES'
nouns = {
'leaf': 'leaves',
'loaf': 'loaves'
@@ -88,7 +88,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_sis(self):
"words ending in SIS"
'words ending in SIS'
nouns = {
'thesis': 'theses'
}
@@ -96,7 +96,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_man(self):
"words ending in MAN"
'words ending in MAN'
nouns = {
'man': 'men',
'mailman': 'mailmen',
@@ -107,7 +107,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_ife(self):
"words ending in IFE"
'words ending in IFE'
nouns = {
'knife': 'knives',
'wife': 'wives',
@@ -117,7 +117,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_eau(self):
"words ending in EAU"
'words ending in EAU'
nouns = {
'tableau': 'tableaux'
}
@@ -125,7 +125,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_elf(self):
"words ending in ELF"
'words ending in ELF'
nouns = {
'elf': 'elves',
'shelf': 'shelves',
@@ -136,7 +136,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_same(self):
"words that are their own plural"
'words that are their own plural'
nouns = {
'sheep': 'sheep',
'deer': 'deer',
@@ -150,7 +150,7 @@ class KnownValues(unittest.TestCase):
self.assertEqual(plural6.plural(singular), plural)
def test_default(self):
"unexceptional words"
'unexceptional words'
nouns = {
'papaya': 'papayas',
'whip': 'whips',
@@ -159,10 +159,7 @@ class KnownValues(unittest.TestCase):
for singular, plural in nouns.items():
self.assertEqual(plural6.plural(singular), plural)
if __name__ == "__main__":
unittest.main()
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+5 -5
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
roman_numeral_map = (('M', 1000),
('CM', 900),
@@ -20,8 +20,8 @@ roman_numeral_map = (('M', 1000),
('I', 1))
def to_roman(n):
"""convert integer to Roman numeral"""
result = ""
'''convert integer to Roman numeral'''
result = ''
for numeral, integer in roman_numeral_map:
while n >= integer:
result += numeral
+11 -11
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
class OutOfRangeError(ValueError): pass
class NotIntegerError(ValueError): pass
@@ -27,26 +27,26 @@ to_roman_table = [ None ]
from_roman_table = {}
def to_roman(n):
"""convert integer to Roman numeral"""
'''convert integer to Roman numeral'''
if not (0 < n < 5000):
raise OutOfRangeError("number out of range (must be 1..4999)")
raise OutOfRangeError('number out of range (must be 1..4999)')
if int(n) != n:
raise NotIntegerError("non-integers can not be converted")
raise NotIntegerError('non-integers can not be converted')
return to_roman_table[n]
def from_roman(s):
"""convert Roman numeral to integer"""
'''convert Roman numeral to integer'''
if not isinstance(s, str):
raise InvalidRomanNumeralError("Input must be a string")
raise InvalidRomanNumeralError('Input must be a string')
if not s:
raise InvalidRomanNumeralError("Input can not be blank")
raise InvalidRomanNumeralError('Input can not be blank')
if s not in from_roman_table:
raise InvalidRomanNumeralError("Invalid Roman numeral: {0}".format(s))
raise InvalidRomanNumeralError('Invalid Roman numeral: {0}'.format(s))
return from_roman_table[s]
def build_lookup_tables():
def to_roman(n):
result = ""
result = ''
for numeral, integer in roman_numeral_map:
if n >= integer:
result = numeral
+6 -6
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
class OutOfRangeError(ValueError):
pass
@@ -22,11 +22,11 @@ roman_numeral_map = (('M', 1000),
('I', 1))
def to_roman(n):
"""convert integer to Roman numeral"""
'''convert integer to Roman numeral'''
if n > 3999:
raise OutOfRangeError("number out of range (must be less than 3999)")
raise OutOfRangeError('number out of range (must be less than 3999)')
result = ""
result = ''
for numeral, integer in roman_numeral_map:
while n >= integer:
result += numeral
+6 -6
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
class OutOfRangeError(ValueError): pass
roman_numeral_map = (('M', 1000),
@@ -21,11 +21,11 @@ roman_numeral_map = (('M', 1000),
('I', 1))
def to_roman(n):
"""convert integer to Roman numeral"""
'''convert integer to Roman numeral'''
if not (0 < n < 4000):
raise OutOfRangeError("number out of range (must be 0..3999)")
raise OutOfRangeError('number out of range (must be 0..3999)')
result = ""
result = ''
for numeral, integer in roman_numeral_map:
while n >= integer:
result += numeral
+7 -7
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
class OutOfRangeError(ValueError): pass
class NotIntegerError(ValueError): pass
@@ -22,13 +22,13 @@ roman_numeral_map = (('M', 1000),
('I', 1))
def to_roman(n):
"""convert integer to Roman numeral"""
'''convert integer to Roman numeral'''
if not (0 < n < 4000):
raise OutOfRangeError("number out of range (must be 0..3999)")
raise OutOfRangeError('number out of range (must be 0..3999)')
if not isinstance(n, int):
raise NotIntegerError("non-integers can not be converted")
raise NotIntegerError('non-integers can not be converted')
result = ""
result = ''
for numeral, integer in roman_numeral_map:
while n >= integer:
result += numeral
+8 -8
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
class OutOfRangeError(ValueError): pass
class NotIntegerError(ValueError): pass
@@ -22,13 +22,13 @@ roman_numeral_map = (('M', 1000),
('I', 1))
def to_roman(n):
"""convert integer to Roman numeral"""
'''convert integer to Roman numeral'''
if not (0 < n < 4000):
raise OutOfRangeError("number out of range (must be 0..3999)")
raise OutOfRangeError('number out of range (must be 0..3999)')
if not isinstance(n, int):
raise NotIntegerError("non-integers can not be converted")
raise NotIntegerError('non-integers can not be converted')
result = ""
result = ''
for numeral, integer in roman_numeral_map:
while n >= integer:
result += numeral
@@ -36,7 +36,7 @@ def to_roman(n):
return result
def from_roman(s):
"""convert Roman numeral to integer"""
'''convert Roman numeral to integer'''
result = 0
index = 0
for numeral, integer in roman_numeral_map:
+11 -11
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import re
class OutOfRangeError(ValueError): pass
@@ -24,7 +24,7 @@ roman_numeral_map = (('M', 1000),
('IV', 4),
('I', 1))
roman_numeral_pattern = re.compile("""
roman_numeral_pattern = re.compile('''
^ # beginning of string
M{0,3} # thousands - 0 to 3 M's
(CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's),
@@ -34,16 +34,16 @@ roman_numeral_pattern = re.compile("""
(IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's),
# or 5-8 (V, followed by 0 to 3 I's)
$ # end of string
""", re.VERBOSE)
''', re.VERBOSE)
def to_roman(n):
"""convert integer to Roman numeral"""
'''convert integer to Roman numeral'''
if not (0 < n < 4000):
raise OutOfRangeError("number out of range (must be 0..3999)")
raise OutOfRangeError('number out of range (must be 0..3999)')
if not isinstance(n, int):
raise NotIntegerError("non-integers can not be converted")
raise NotIntegerError('non-integers can not be converted')
result = ""
result = ''
for numeral, integer in roman_numeral_map:
while n >= integer:
result += numeral
@@ -51,9 +51,9 @@ def to_roman(n):
return result
def from_roman(s):
"""convert Roman numeral to integer"""
'''convert Roman numeral to integer'''
if not roman_numeral_pattern.search(s):
raise InvalidRomanNumeralError("Invalid Roman numeral: {0}".format(s))
raise InvalidRomanNumeralError('Invalid Roman numeral: {0}'.format(s))
result = 0
index = 0
+12 -12
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import re
class OutOfRangeError(ValueError): pass
@@ -24,7 +24,7 @@ roman_numeral_map = (('M', 1000),
('IV', 4),
('I', 1))
roman_numeral_pattern = re.compile("""
roman_numeral_pattern = re.compile('''
^ # beginning of string
M{0,3} # thousands - 0 to 3 M's
(CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's),
@@ -34,16 +34,16 @@ roman_numeral_pattern = re.compile("""
(IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's),
# or 5-8 (V, followed by 0 to 3 I's)
$ # end of string
""", re.VERBOSE)
''', re.VERBOSE)
def to_roman(n):
"""convert integer to Roman numeral"""
'''convert integer to Roman numeral'''
if not (0 < n < 4000):
raise OutOfRangeError("number out of range (must be 0..3999)")
raise OutOfRangeError('number out of range (must be 0..3999)')
if not isinstance(n, int):
raise NotIntegerError("non-integers can not be converted")
raise NotIntegerError('non-integers can not be converted')
result = ""
result = ''
for numeral, integer in roman_numeral_map:
while n >= integer:
result += numeral
@@ -51,11 +51,11 @@ def to_roman(n):
return result
def from_roman(s):
"""convert Roman numeral to integer"""
'''convert Roman numeral to integer'''
if not isinstance(s, str):
raise InvalidRomanNumeralError("Input must be a string")
raise InvalidRomanNumeralError('Input must be a string')
if not roman_numeral_pattern.search(s):
raise InvalidRomanNumeralError("Invalid Roman numeral: {0}".format(s))
raise InvalidRomanNumeralError('Invalid Roman numeral: {0}'.format(s))
result = 0
index = 0
+13 -13
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import re
class OutOfRangeError(ValueError): pass
@@ -24,7 +24,7 @@ roman_numeral_map = (('M', 1000),
('IV', 4),
('I', 1))
roman_numeral_pattern = re.compile("""
roman_numeral_pattern = re.compile('''
^ # beginning of string
M{0,3} # thousands - 0 to 3 M's
(CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's),
@@ -34,16 +34,16 @@ roman_numeral_pattern = re.compile("""
(IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's),
# or 5-8 (V, followed by 0 to 3 I's)
$ # end of string
""", re.VERBOSE)
''', re.VERBOSE)
def to_roman(n):
"""convert integer to Roman numeral"""
'''convert integer to Roman numeral'''
if not (0 < n < 4000):
raise OutOfRangeError("number out of range (must be 0..3999)")
raise OutOfRangeError('number out of range (must be 0..3999)')
if not isinstance(n, int):
raise NotIntegerError("non-integers can not be converted")
raise NotIntegerError('non-integers can not be converted')
result = ""
result = ''
for numeral, integer in roman_numeral_map:
while n >= integer:
result += numeral
@@ -51,13 +51,13 @@ def to_roman(n):
return result
def from_roman(s):
"""convert Roman numeral to integer"""
'''convert Roman numeral to integer'''
if not isinstance(s, str):
raise InvalidRomanNumeralError("Input must be a string")
raise InvalidRomanNumeralError('Input must be a string')
if not s:
raise InvalidRomanNumeralError("Input can not be blank")
raise InvalidRomanNumeralError('Input can not be blank')
if not roman_numeral_pattern.search(s):
raise InvalidRomanNumeralError("Invalid Roman numeral: {0}".format(s))
raise InvalidRomanNumeralError('Invalid Roman numeral: {0}'.format(s))
result = 0
index = 0
+13 -13
View File
@@ -1,9 +1,9 @@
"""Convert to and from Roman numerals
'''Convert to and from Roman numerals
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import re
class OutOfRangeError(ValueError): pass
@@ -24,7 +24,7 @@ roman_numeral_map = (('M', 1000),
('IV', 4),
('I', 1))
roman_numeral_pattern = re.compile("""
roman_numeral_pattern = re.compile('''
^ # beginning of string
M{0,4} # thousands - 0 to 4 M's
(CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's),
@@ -34,16 +34,16 @@ roman_numeral_pattern = re.compile("""
(IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's),
# or 5-8 (V, followed by 0 to 3 I's)
$ # end of string
""", re.VERBOSE)
''', re.VERBOSE)
def to_roman(n):
"""convert integer to Roman numeral"""
'''convert integer to Roman numeral'''
if not (0 < n < 5000):
raise OutOfRangeError("number out of range (must be 0..4999)")
raise OutOfRangeError('number out of range (must be 0..4999)')
if not isinstance(n, int):
raise NotIntegerError("non-integers can not be converted")
raise NotIntegerError('non-integers can not be converted')
result = ""
result = ''
for numeral, integer in roman_numeral_map:
while n >= integer:
result += numeral
@@ -51,13 +51,13 @@ def to_roman(n):
return result
def from_roman(s):
"""convert Roman numeral to integer"""
'''convert Roman numeral to integer'''
if not isinstance(s, str):
raise InvalidRomanNumeralError("Input must be a string")
raise InvalidRomanNumeralError('Input must be a string')
if not s:
raise InvalidRomanNumeralError("Input can not be blank")
raise InvalidRomanNumeralError('Input can not be blank')
if not roman_numeral_pattern.search(s):
raise InvalidRomanNumeralError("Invalid Roman numeral: {0}".format(s))
raise InvalidRomanNumeralError('Invalid Roman numeral: {0}'.format(s))
result = 0
index = 0
+5 -5
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman1
import unittest
@@ -67,12 +67,12 @@ class KnownValues(unittest.TestCase):
(3999, 'MMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman1.to_roman(integer)
self.assertEqual(numeral, result)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+17 -17
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman10
import unittest
@@ -71,68 +71,68 @@ class KnownValues(unittest.TestCase):
(4999, 'MMMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman10.to_roman(integer)
self.assertEqual(numeral, result)
def test_from_roman_known_values(self):
"""from_roman should give known result with known input"""
'''from_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman10.from_roman(numeral)
self.assertEqual(integer, result)
class ToRomanBadInput(unittest.TestCase):
def test_too_large(self):
"""to_roman should fail with large input"""
'''to_roman should fail with large input'''
self.assertRaises(roman10.OutOfRangeError, roman10.to_roman, 5000)
def test_zero(self):
"""to_roman should fail with 0 input"""
'''to_roman should fail with 0 input'''
self.assertRaises(roman10.OutOfRangeError, roman10.to_roman, 0)
def test_negative(self):
"""to_roman should fail with negative input"""
'''to_roman should fail with negative input'''
self.assertRaises(roman10.OutOfRangeError, roman10.to_roman, -1)
def test_non_integer(self):
"""to_roman should fail with non-integer input"""
'''to_roman should fail with non-integer input'''
self.assertRaises(roman10.NotIntegerError, roman10.to_roman, 0.5)
class FromRomanBadInput(unittest.TestCase):
def test_too_many_repeated_numerals(self):
"""from_roman should fail with too many repeated numerals"""
'''from_roman should fail with too many repeated numerals'''
for s in ('MMMMM', 'DD', 'CCCC', 'LL', 'XXXX', 'VV', 'IIII'):
self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, s)
def test_repeated_pairs(self):
"""from_roman should fail with repeated pairs of numerals"""
'''from_roman should fail with repeated pairs of numerals'''
for s in ('CMCM', 'CDCD', 'XCXC', 'XLXL', 'IXIX', 'IVIV'):
self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, s)
def test_malformed_antecedents(self):
"""from_roman should fail with malformed antecedents"""
'''from_roman should fail with malformed antecedents'''
for s in ('IIMXCC', 'VX', 'DCM', 'CMM', 'IXIV',
'MCMC', 'XCX', 'IVI', 'LM', 'LD', 'LC'):
self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, s)
def test_blank(self):
"""from_roman should fail with blank string"""
self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, "")
'''from_roman should fail with blank string'''
self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, '')
def test_non_string(self):
"""from_roman should fail with non-string input"""
'''from_roman should fail with non-string input'''
self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, 1)
class RoundtripCheck(unittest.TestCase):
def test_roundtrip(self):
"""from_roman(to_roman(n))==n for all n"""
'''from_roman(to_roman(n))==n for all n'''
for integer in range(1, 5000):
numeral = roman10.to_roman(integer)
result = roman10.from_roman(numeral)
self.assertEqual(integer, result)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+6 -6
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman2
import unittest
@@ -67,17 +67,17 @@ class KnownValues(unittest.TestCase):
(3999, 'MMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman2.to_roman(integer)
self.assertEqual(numeral, result)
class ToRomanBadInput(unittest.TestCase):
def test_too_large(self):
"""to_roman should fail with large input"""
'''to_roman should fail with large input'''
self.assertRaises(roman2.OutOfRangeError, roman2.to_roman, 4000)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+8 -8
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman3
import unittest
@@ -67,25 +67,25 @@ class KnownValues(unittest.TestCase):
(3999, 'MMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman3.to_roman(integer)
self.assertEqual(numeral, result)
class ToRomanBadInput(unittest.TestCase):
def test_too_large(self):
"""to_roman should fail with large input"""
'''to_roman should fail with large input'''
self.assertRaises(roman3.OutOfRangeError, roman3.to_roman, 4000)
def test_zero(self):
"""to_roman should fail with 0 input"""
'''to_roman should fail with 0 input'''
self.assertRaises(roman3.OutOfRangeError, roman3.to_roman, 0)
def test_negative(self):
"""to_roman should fail with negative input"""
'''to_roman should fail with negative input'''
self.assertRaises(roman3.OutOfRangeError, roman3.to_roman, -1)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+9 -9
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman4
import unittest
@@ -67,29 +67,29 @@ class KnownValues(unittest.TestCase):
(3999, 'MMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman4.to_roman(integer)
self.assertEqual(numeral, result)
class ToRomanBadInput(unittest.TestCase):
def test_too_large(self):
"""to_roman should fail with large input"""
'''to_roman should fail with large input'''
self.assertRaises(roman4.OutOfRangeError, roman4.to_roman, 4000)
def test_zero(self):
"""to_roman should fail with 0 input"""
'''to_roman should fail with 0 input'''
self.assertRaises(roman4.OutOfRangeError, roman4.to_roman, 0)
def test_negative(self):
"""to_roman should fail with negative input"""
'''to_roman should fail with negative input'''
self.assertRaises(roman4.OutOfRangeError, roman4.to_roman, -1)
def test_non_integer(self):
"""to_roman should fail with non-integer input"""
'''to_roman should fail with non-integer input'''
self.assertRaises(roman4.NotIntegerError, roman4.to_roman, 0.5)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+11 -11
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman5
import unittest
@@ -67,43 +67,43 @@ class KnownValues(unittest.TestCase):
(3999, 'MMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman5.to_roman(integer)
self.assertEqual(numeral, result)
def test_from_roman_known_values(self):
"""from_roman should give known result with known input"""
'''from_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman5.from_roman(numeral)
self.assertEqual(integer, result)
class ToRomanBadInput(unittest.TestCase):
def test_too_large(self):
"""to_roman should fail with large input"""
'''to_roman should fail with large input'''
self.assertRaises(roman5.OutOfRangeError, roman5.to_roman, 4000)
def test_zero(self):
"""to_roman should fail with 0 input"""
'''to_roman should fail with 0 input'''
self.assertRaises(roman5.OutOfRangeError, roman5.to_roman, 0)
def test_negative(self):
"""to_roman should fail with negative input"""
'''to_roman should fail with negative input'''
self.assertRaises(roman5.OutOfRangeError, roman5.to_roman, -1)
def test_non_integer(self):
"""to_roman should fail with non-integer input"""
'''to_roman should fail with non-integer input'''
self.assertRaises(roman5.NotIntegerError, roman5.to_roman, 0.5)
class RoundtripCheck(unittest.TestCase):
def test_roundtrip(self):
"""from_roman(to_roman(n))==n for all n"""
'''from_roman(to_roman(n))==n for all n'''
for integer in range(1, 4000):
numeral = roman5.to_roman(integer)
result = roman5.from_roman(numeral)
self.assertEqual(integer, result)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+14 -14
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman6
import unittest
@@ -67,60 +67,60 @@ class KnownValues(unittest.TestCase):
(3999, 'MMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman6.to_roman(integer)
self.assertEqual(numeral, result)
def test_from_roman_known_values(self):
"""from_roman should give known result with known input"""
'''from_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman6.from_roman(numeral)
self.assertEqual(integer, result)
class ToRomanBadInput(unittest.TestCase):
def test_too_large(self):
"""to_roman should fail with large input"""
'''to_roman should fail with large input'''
self.assertRaises(roman6.OutOfRangeError, roman6.to_roman, 4000)
def test_zero(self):
"""to_roman should fail with 0 input"""
'''to_roman should fail with 0 input'''
self.assertRaises(roman6.OutOfRangeError, roman6.to_roman, 0)
def test_negative(self):
"""to_roman should fail with negative input"""
'''to_roman should fail with negative input'''
self.assertRaises(roman6.OutOfRangeError, roman6.to_roman, -1)
def test_non_integer(self):
"""to_roman should fail with non-integer input"""
'''to_roman should fail with non-integer input'''
self.assertRaises(roman6.NotIntegerError, roman6.to_roman, 0.5)
class FromRomanBadInput(unittest.TestCase):
def test_too_many_repeated_numerals(self):
"""from_roman should fail with too many repeated numerals"""
'''from_roman should fail with too many repeated numerals'''
for s in ('MMMM', 'DD', 'CCCC', 'LL', 'XXXX', 'VV', 'IIII'):
self.assertRaises(roman6.InvalidRomanNumeralError, roman6.from_roman, s)
def test_repeated_pairs(self):
"""from_roman should fail with repeated pairs of numerals"""
'''from_roman should fail with repeated pairs of numerals'''
for s in ('CMCM', 'CDCD', 'XCXC', 'XLXL', 'IXIX', 'IVIV'):
self.assertRaises(roman6.InvalidRomanNumeralError, roman6.from_roman, s)
def test_malformed_antecedents(self):
"""from_roman should fail with malformed antecedents"""
'''from_roman should fail with malformed antecedents'''
for s in ('IIMXCC', 'VX', 'DCM', 'CMM', 'IXIV',
'MCMC', 'XCX', 'IVI', 'LM', 'LD', 'LC'):
self.assertRaises(roman6.InvalidRomanNumeralError, roman6.from_roman, s)
class RoundtripCheck(unittest.TestCase):
def test_roundtrip(self):
"""from_roman(to_roman(n))==n for all n"""
'''from_roman(to_roman(n))==n for all n'''
for integer in range(1, 4000):
numeral = roman6.to_roman(integer)
result = roman6.from_roman(numeral)
self.assertEqual(integer, result)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+15 -15
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman7
import unittest
@@ -67,64 +67,64 @@ class KnownValues(unittest.TestCase):
(3999, 'MMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman7.to_roman(integer)
self.assertEqual(numeral, result)
def test_from_roman_known_values(self):
"""from_roman should give known result with known input"""
'''from_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman7.from_roman(numeral)
self.assertEqual(integer, result)
class ToRomanBadInput(unittest.TestCase):
def test_too_large(self):
"""to_roman should fail with large input"""
'''to_roman should fail with large input'''
self.assertRaises(roman7.OutOfRangeError, roman7.to_roman, 4000)
def test_zero(self):
"""to_roman should fail with 0 input"""
'''to_roman should fail with 0 input'''
self.assertRaises(roman7.OutOfRangeError, roman7.to_roman, 0)
def test_negative(self):
"""to_roman should fail with negative input"""
'''to_roman should fail with negative input'''
self.assertRaises(roman7.OutOfRangeError, roman7.to_roman, -1)
def test_non_integer(self):
"""to_roman should fail with non-integer input"""
'''to_roman should fail with non-integer input'''
self.assertRaises(roman7.NotIntegerError, roman7.to_roman, 0.5)
class FromRomanBadInput(unittest.TestCase):
def test_too_many_repeated_numerals(self):
"""from_roman should fail with too many repeated numerals"""
'''from_roman should fail with too many repeated numerals'''
for s in ('MMMM', 'DD', 'CCCC', 'LL', 'XXXX', 'VV', 'IIII'):
self.assertRaises(roman7.InvalidRomanNumeralError, roman7.from_roman, s)
def test_repeated_pairs(self):
"""from_roman should fail with repeated pairs of numerals"""
'''from_roman should fail with repeated pairs of numerals'''
for s in ('CMCM', 'CDCD', 'XCXC', 'XLXL', 'IXIX', 'IVIV'):
self.assertRaises(roman7.InvalidRomanNumeralError, roman7.from_roman, s)
def test_malformed_antecedents(self):
"""from_roman should fail with malformed antecedents"""
'''from_roman should fail with malformed antecedents'''
for s in ('IIMXCC', 'VX', 'DCM', 'CMM', 'IXIV',
'MCMC', 'XCX', 'IVI', 'LM', 'LD', 'LC'):
self.assertRaises(roman7.InvalidRomanNumeralError, roman7.from_roman, s)
def test_non_string(self):
"""from_roman should fail with non-string input"""
'''from_roman should fail with non-string input'''
self.assertRaises(roman7.InvalidRomanNumeralError, roman7.from_roman, 1)
class RoundtripCheck(unittest.TestCase):
def test_roundtrip(self):
"""from_roman(to_roman(n))==n for all n"""
'''from_roman(to_roman(n))==n for all n'''
for integer in range(1, 4000):
numeral = roman7.to_roman(integer)
result = roman7.from_roman(numeral)
self.assertEqual(integer, result)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+17 -17
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman8
import unittest
@@ -67,68 +67,68 @@ class KnownValues(unittest.TestCase):
(3999, 'MMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman8.to_roman(integer)
self.assertEqual(numeral, result)
def test_from_roman_known_values(self):
"""from_roman should give known result with known input"""
'''from_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman8.from_roman(numeral)
self.assertEqual(integer, result)
class ToRomanBadInput(unittest.TestCase):
def test_too_large(self):
"""to_roman should fail with large input"""
'''to_roman should fail with large input'''
self.assertRaises(roman8.OutOfRangeError, roman8.to_roman, 4000)
def test_zero(self):
"""to_roman should fail with 0 input"""
'''to_roman should fail with 0 input'''
self.assertRaises(roman8.OutOfRangeError, roman8.to_roman, 0)
def test_negative(self):
"""to_roman should fail with negative input"""
'''to_roman should fail with negative input'''
self.assertRaises(roman8.OutOfRangeError, roman8.to_roman, -1)
def test_non_integer(self):
"""to_roman should fail with non-integer input"""
'''to_roman should fail with non-integer input'''
self.assertRaises(roman8.NotIntegerError, roman8.to_roman, 0.5)
class FromRomanBadInput(unittest.TestCase):
def test_too_many_repeated_numerals(self):
"""from_roman should fail with too many repeated numerals"""
'''from_roman should fail with too many repeated numerals'''
for s in ('MMMM', 'DD', 'CCCC', 'LL', 'XXXX', 'VV', 'IIII'):
self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, s)
def test_repeated_pairs(self):
"""from_roman should fail with repeated pairs of numerals"""
'''from_roman should fail with repeated pairs of numerals'''
for s in ('CMCM', 'CDCD', 'XCXC', 'XLXL', 'IXIX', 'IVIV'):
self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, s)
def test_malformed_antecedents(self):
"""from_roman should fail with malformed antecedents"""
'''from_roman should fail with malformed antecedents'''
for s in ('IIMXCC', 'VX', 'DCM', 'CMM', 'IXIV',
'MCMC', 'XCX', 'IVI', 'LM', 'LD', 'LC'):
self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, s)
def test_blank(self):
"""from_roman should fail with blank string"""
self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, "")
'''from_roman should fail with blank string'''
self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, '')
def test_non_string(self):
"""from_roman should fail with non-string input"""
'''from_roman should fail with non-string input'''
self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, 1)
class RoundtripCheck(unittest.TestCase):
def test_roundtrip(self):
"""from_roman(to_roman(n))==n for all n"""
'''from_roman(to_roman(n))==n for all n'''
for integer in range(1, 4000):
numeral = roman8.to_roman(integer)
result = roman8.from_roman(numeral)
self.assertEqual(integer, result)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.
+17 -17
View File
@@ -1,9 +1,9 @@
"""Unit test for roman1.py
'''Unit test for roman1.py
This program is part of "Dive Into Python 3", a free Python book for
This program is part of 'Dive Into Python 3', a free Python book for
experienced programmers. Visit http://diveintopython3.org/ for the
latest version.
"""
'''
import roman9
import unittest
@@ -71,68 +71,68 @@ class KnownValues(unittest.TestCase):
(4999, 'MMMMCMXCIX'))
def test_to_roman_known_values(self):
"""to_roman should give known result with known input"""
'''to_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman9.to_roman(integer)
self.assertEqual(numeral, result)
def test_from_roman_known_values(self):
"""from_roman should give known result with known input"""
'''from_roman should give known result with known input'''
for integer, numeral in self.known_values:
result = roman9.from_roman(numeral)
self.assertEqual(integer, result)
class ToRomanBadInput(unittest.TestCase):
def test_too_large(self):
"""to_roman should fail with large input"""
'''to_roman should fail with large input'''
self.assertRaises(roman9.OutOfRangeError, roman9.to_roman, 5000)
def test_zero(self):
"""to_roman should fail with 0 input"""
'''to_roman should fail with 0 input'''
self.assertRaises(roman9.OutOfRangeError, roman9.to_roman, 0)
def test_negative(self):
"""to_roman should fail with negative input"""
'''to_roman should fail with negative input'''
self.assertRaises(roman9.OutOfRangeError, roman9.to_roman, -1)
def test_non_integer(self):
"""to_roman should fail with non-integer input"""
'''to_roman should fail with non-integer input'''
self.assertRaises(roman9.NotIntegerError, roman9.to_roman, 0.5)
class FromRomanBadInput(unittest.TestCase):
def test_too_many_repeated_numerals(self):
"""from_roman should fail with too many repeated numerals"""
'''from_roman should fail with too many repeated numerals'''
for s in ('MMMMM', 'DD', 'CCCC', 'LL', 'XXXX', 'VV', 'IIII'):
self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, s)
def test_repeated_pairs(self):
"""from_roman should fail with repeated pairs of numerals"""
'''from_roman should fail with repeated pairs of numerals'''
for s in ('CMCM', 'CDCD', 'XCXC', 'XLXL', 'IXIX', 'IVIV'):
self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, s)
def test_malformed_antecedents(self):
"""from_roman should fail with malformed antecedents"""
'''from_roman should fail with malformed antecedents'''
for s in ('IIMXCC', 'VX', 'DCM', 'CMM', 'IXIV',
'MCMC', 'XCX', 'IVI', 'LM', 'LD', 'LC'):
self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, s)
def test_blank(self):
"""from_roman should fail with blank string"""
self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, "")
'''from_roman should fail with blank string'''
self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, '')
def test_non_string(self):
"""from_roman should fail with non-string input"""
'''from_roman should fail with non-string input'''
self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, 1)
class RoundtripCheck(unittest.TestCase):
def test_roundtrip(self):
"""from_roman(to_roman(n))==n for all n"""
'''from_roman(to_roman(n))==n for all n'''
for integer in range(1, 5000):
numeral = roman9.to_roman(integer)
result = roman9.from_roman(numeral)
self.assertEqual(integer, result)
if __name__ == "__main__":
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2009, Mark Pilgrim, All rights reserved.