1. Enrico Franchi
  2. pyfiboheap

Commits

Enrico Franchi  committed 6fe7ce1

Split tests in their own test files.

  • Participants
  • Parent commits 071cd36
  • Branches default

Comments (0)

Files changed (8)

File tests/fibonacci_tree_test.py

-import fiboheaps
-import random
-import unittest
-
-class TestFibonacciEmpty(unittest.TestCase):
-    def setUp(self):
-        self.heap = fiboheaps.FibonacciHeap()
-
-    def testEmpty(self):
-        self.assertEquals(0, len(self.heap))
-
-    def testAddElement(self):
-        self.heap.push('foo')
-        self.assertEquals(1, len(self.heap))
-
-    def testRemoveElementEmptyFib(self):
-        self.assertRaises(IndexError, self.heap.pop)
-
-    def testPeekEmptyFib(self):
-        self.assertRaises(IndexError, self.heap.peek)
-
-class CountingInstances(object):
-    instances = 0
-
-    def __init__(self):
-        CountingInstances.instances += 1
-
-    def __del__(self):
-        CountingInstances.instances -= 1
-
-class TestOwnership(unittest.TestCase):
-    def setUp(self):
-        self.heap = fiboheaps.FibonacciHeap()
-        self.inst = CountingInstances.instances
-
-    def testOwnership(self):
-        self.heap.push(CountingInstances())
-        inc_inst = CountingInstances.instances
-        self.assertEquals(self.inst + 1, inc_inst)
-
-    def testClear(self):
-        for _ in xrange(1000):
-            self.heap.push(CountingInstances())
-        del self.heap
-        self.assertEquals(self.inst, CountingInstances.instances)
-
-class TestFibonacciOneElement(unittest.TestCase):
-    def setUp(self):
-        self.heap = fiboheaps.FibonacciHeap()
-        self.element = 'spam'
-        self.heap.push(self.element)
-
-    def testPeek(self):
-        var = self.heap.peek()
-        self.assertEquals(self.element, var)
-        self.assertEquals(1, len(self.heap))
-
-    def testRemoveElement(self):
-        self.heap.pop()
-        self.assertEquals(0, len(self.heap))
-
-    def testExtend(self):
-        lst = ['foo', 'bar', 'baz']
-        full_lst = sorted([self.element] + lst)
-        self.heap.extend(lst)
-        self.assertEquals(len(full_lst), len(self.heap))
-
-class TestOrder(unittest.TestCase):
-    def setUp(self):
-        self.heap = fiboheaps.FibonacciHeap()
-        self.sequence = list(range(10))
-        self.scrambled_sequence = list(self.sequence)
-        random.shuffle(self.scrambled_sequence)
-        for element in self.scrambled_sequence:
-            self.heap.push(element)
-
-    def testMinProperties(self):
-        for el in self.sequence:
-            self.assertEqual(el, self.heap.pop())
-        self.assertEquals(0, len(self.heap))
-
-    def testLen(self):
-        self.assertEquals(len(self.sequence), len(self.heap))
-
-    def testIterEasy(self):
-        self.assertSetEqual(
-                set(self.sequence),
-                set(iter(self.heap)))
-
-    def testIterHard(self):
-        self.heap.peek() # forces consolidate
-        self.assertSetEqual(
-                set(self.sequence),
-                set(iter(self.heap)))
-
-    def testCopy(self):
-        copy = self.heap.copy()
-        self.assertSetEqual(
-            set(self.heap),
-            set(copy))

File tests/test_copy.py

View file
+import fiboheaps
+import unittest
+
+class TestCopy(unittest.TestCase):
+    def setUp(self):
+        self.heap = fiboheaps.FibonacciHeap()
+        self.heap.extend(range(100))
+
+    def testCopy(self):
+        copy = self.heap.copy()
+        self.assertSetEqual(
+            set(self.heap),
+            set(copy))
+

File tests/test_empty_tree.py

View file
+import fiboheaps
+import unittest
+
+class TestFibonacciEmpty(unittest.TestCase):
+    def setUp(self):
+        self.heap = fiboheaps.FibonacciHeap()
+
+    def testEmpty(self):
+        self.assertEquals(0, len(self.heap))
+
+    def testAddElement(self):
+        self.heap.push('foo')
+        self.assertEquals(1, len(self.heap))
+
+    def testRemoveElementEmptyFib(self):
+        self.assertRaises(IndexError, self.heap.pop)
+
+    def testPeekEmptyFib(self):
+        self.assertRaises(IndexError, self.heap.peek)

File tests/test_iter.py

View file
+import fiboheaps
+import unittest
+
+class TestIter(unittest.TestCase):
+    def setUp(self):
+        self.heap = fiboheaps.FibonacciHeap()
+        self.sequence = list(range(10))
+        self.heap.extend(self.sequence)
+
+    def testLen(self):
+        self.assertEquals(len(self.sequence), len(self.heap))
+
+    def testIterEasy(self):
+        self.assertSetEqual(
+                set(self.sequence),
+                set(iter(self.heap)))
+
+    def testIterHard(self):
+        self.heap.peek() # forces consolidate
+        self.assertSetEqual(
+                set(self.sequence),
+                set(iter(self.heap)))

File tests/test_merge.py

View file
+import fiboheaps
+import unittest
+
+
+
+class TestMerge(unittest.TestCase):
+    def setUp(self):
+        self.first = fiboheaps.FibonacciHeap()
+        self.first_contents = range(4)
+        self.first.extend(self.first_contents)
+        self.second = fiboheaps.FibonacciHeap()
+        self.second_contents = range(7, 10)
+        self.second.extend(self.second_contents)
+
+
+    def testMergeOne(self):
+        self.first.merge(self.second)
+        self.assertSetEqual(
+            set(self.second),
+            set(self.second_contents))
+        self.assertSetEqual(
+            set(self.first),
+            set(self.first_contents + self.second_contents))
+
+    def testMergeOneWithPeek(self):
+        self.first.merge(self.second)
+        self.assertEqual(
+            self.first.peek(),
+            min(self.first_contents + self.second_contents))
+        self.assertEqual(
+            self.second.peek(), min(self.second_contents))
+        self.assertSetEqual(
+            set(self.second),
+            set(self.second_contents))
+        self.assertSetEqual(
+            set(self.first),
+            set(self.first_contents + self.second_contents))
+
+    def testMergeTwo(self):
+        self.second.merge(self.first)
+        self.assertSetEqual(
+            set(self.first),
+            set(self.first_contents))
+        self.assertSetEqual(
+            set(self.second),
+            set(self.first_contents + self.second_contents))
+
+    def testMergeTwoWithPeek(self):
+        self.second.merge(self.first)
+        self.assertEqual(
+            self.second.peek(),
+            min(self.first_contents + self.second_contents))
+        self.assertEqual(
+            self.first.peek(), min(self.first_contents))
+        self.assertSetEqual(
+            set(self.first),
+            set(self.first_contents))
+        self.assertSetEqual(
+            set(self.second),
+            set(self.first_contents + self.second_contents))
+

File tests/test_oneelement.py

View file
+import fiboheaps
+import unittest
+
+class TestFibonacciOneElement(unittest.TestCase):
+    def setUp(self):
+        self.heap = fiboheaps.FibonacciHeap()
+        self.element = 'spam'
+        self.heap.push(self.element)
+
+    def testPeek(self):
+        var = self.heap.peek()
+        self.assertEquals(self.element, var)
+        self.assertEquals(1, len(self.heap))
+
+    def testRemoveElement(self):
+        self.heap.pop()
+        self.assertEquals(0, len(self.heap))
+
+    def testExtend(self):
+        lst = ['foo', 'bar', 'baz']
+        full_lst = sorted([self.element] + lst)
+        self.heap.extend(lst)
+        self.assertEquals(len(full_lst), len(self.heap))

File tests/test_order.py

View file
+import fiboheaps
+import unittest
+import random
+
+class TestOrder(unittest.TestCase):
+    def setUp(self):
+        self.heap = fiboheaps.FibonacciHeap()
+        self.sequence = list(range(10))
+        self.scrambled_sequence = list(self.sequence)
+        random.shuffle(self.scrambled_sequence)
+        for element in self.scrambled_sequence:
+            self.heap.push(element)
+
+    def testMinProperties(self):
+        for el in self.sequence:
+            self.assertEqual(el, self.heap.pop())
+        self.assertEquals(0, len(self.heap))
+
+    def testLen(self):
+        self.assertEquals(len(self.sequence), len(self.heap))
+
+    def testIterEasy(self):
+        self.assertSetEqual(
+                set(self.sequence),
+                set(iter(self.heap)))
+
+    def testIterHard(self):
+        self.heap.peek() # forces consolidate
+        self.assertSetEqual(
+                set(self.sequence),
+                set(iter(self.heap)))
+
+    def testCopy(self):
+        copy = self.heap.copy()
+        self.assertSetEqual(
+            set(self.heap),
+            set(copy))

File tests/test_ownership.py

View file
+import fiboheaps
+import unittest
+
+class CountingInstances(object):
+    instances = 0
+
+    def __init__(self):
+        CountingInstances.instances += 1
+
+    def __del__(self):
+        CountingInstances.instances -= 1
+
+class TestOwnership(unittest.TestCase):
+    def setUp(self):
+        self.heap = fiboheaps.FibonacciHeap()
+        self.inst = CountingInstances.instances
+
+    def testOwnership(self):
+        self.heap.push(CountingInstances())
+        inc_inst = CountingInstances.instances
+        self.assertEquals(self.inst + 1, inc_inst)
+
+    def testClear(self):
+        for _ in xrange(1000):
+            self.heap.push(CountingInstances())
+        del self.heap
+        self.assertEquals(self.inst, CountingInstances.instances)
+
+
+
+
+