From 83efb118c1bdcb7d44a1fa6b187eb33bf86f72dd Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Tue, 28 Oct 2008 18:25:54 -0400 Subject: Replaced Treap with OrderedDict. Updated regression_tests and extensions. All tests pass. Still needs documentation. --- regression-tests.py | 137 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 57 deletions(-) (limited to 'regression-tests.py') diff --git a/regression-tests.py b/regression-tests.py index c8f784c..09dd313 100755 --- a/regression-tests.py +++ b/regression-tests.py @@ -75,74 +75,97 @@ class TestHtmlStash(unittest.TestCase): self.assertEqual(self.stash.html_counter, 0) self.assertEqual(self.stash.rawHtmlBlocks, []) -class TestTreap(unittest.TestCase): - """ Test Treap storage class. """ +class TestOrderedDict(unittest.TestCase): + """ Test OrderedDict storage class. """ def setUp(self): - self.treap = markdown.Treap() - self.treap.add('first', 'This', '_begin') - self.treap.add('second', 'is', '>first') - self.treap.add('fourth', 'self', '>second') - self.treap.add('fifth', 'test', '>fourth') - self.treap.add('third', 'a', '>second') - self.treap['seventh'] = '.' - - def testHeapsorted(self): - """ Test output of Treap.heapsorted(). """ - self.assertEqual(self.treap.heapsorted(), - ['This', 'is', 'a', 'self', 'test','.']) - self.assertEqual(self.treap.heapsorted(keys=1), - ['first', 'second', 'third', 'fourth', 'fifth','seventh']) - self.assertEqual(self.treap.heapsorted(items=1), + self.odict = markdown.OrderedDict() + self.odict['first'] = 'This' + self.odict['third'] = 'a' + self.odict['fourth'] = 'self' + self.odict['fifth'] = 'test' + + def testValues(self): + """ Test output of OrderedDict.values(). """ + self.assertEqual(self.odict.values(), ['This', 'a', 'self', 'test']) + + def testKeys(self): + """ Test output of OrderedDict.keys(). """ + self.assertEqual(self.odict.keys(), + ['first', 'third', 'fourth', 'fifth']) + + def testItems(self): + """ Test output of OrderedDict.items(). """ + self.assertEqual(self.odict.items(), + [('first', 'This'), ('third', 'a'), + ('fourth', 'self'), ('fifth', 'test')]) + + def testAddBefore(self): + """ Test adding an OrderedDict item before a given key. """ + self.odict.add('second', 'is', 'first') + self.assertEqual(self.odict.items(), [('first', 'This'), ('second', 'is'), ('third', 'a'), - ('fourth', 'self'), ('seventh','.'), ('fifth', 'test')]) + ('fourth', 'self'), ('fifth', 'test')]) + + def testAddAfterEnd(self): + """ Test adding an OrderedDict item after the last key. """ + self.odict.add('sixth', '.', '>fifth') + self.assertEqual(self.odict.items(), + [('first', 'This'), ('third', 'a'), + ('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')]) + + def testAdd_begin(self): + """ Test adding an OrderedDict item using "_begin". """ + self.odict.add('zero', 'CRAZY', '_begin') + self.assertEqual(self.odict.items(), + [('zero', 'CRAZY'), ('first', 'This'), ('third', 'a'), + ('fourth', 'self'), ('fifth', 'test')]) + + def testAdd_end(self): + """ Test adding an OrderedDict item using "_end". """ + self.odict.add('sixth', '.', '_end') + self.assertEqual(self.odict.items(), + [('first', 'This'), ('third', 'a'), + ('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')]) + + def testAddBadLocation(self): + """ Test Error on bad location in OrderedDict.add(). """ + self.assertRaises(ValueError, self.odict.add, 'sixth', '.', '