<commit_before><commit_msg>Added test for union find class.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_union_find
----------------------------------

Tests for `python_algorithms.union_find` module.
"""

import unittest

from python_algorithms.basic.union_find import UF


class TestUnionFind(unittest.TestCase):

    def setUp(self):
        self.N = 10
        self.uf = UF(self.N)
        self.pairs = ((0, 1), (1, 2), (4, 5), (7, 8), (8, 9))

    def test_count(self):
        self.assertEqual(self.uf.count(), self.N)
        self.assertEqual(self.count_sets(), self.N)

        for x, y in self.pairs:
            self.uf.union(x, y)
        n = self.N - len(self.pairs)
        self.assertEqual(self.uf.count(), n)
        self.assertEqual(self.count_sets(), n)

    def test_str_empty_uf(self):
        self.assertEqual(str(UF(0)), "")

    def test_str_stack(self):
        self.assertEqual(str(self.uf), " ".join([str(x) for x in range(self.N)]))

    def count_sets(self):
        return len(set([self.uf.find(x) for x in range(self.N)]))

    def tearDown(self):
        pass

if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.18518518518518517, 'fraction_numerical': 0.012058570198105082, 'mean_word_length': 2.4583333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4987353', 'n_tokens_mistral': 416, 'n_tokens_neox': 399, 'n_words': 85}