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))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.