1. Enrico Franchi
  2. pyfiboheap

Source

pyfiboheap / tests / test_merge.py

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))

    def testMergeNotTree(self):
        self.assertRaises(TypeError, self.first.merge, range(10))