<commit_before>import unittest
import networkx as nx
import random

import infomap

def girvan_graphs(zout) :
    """
    Create a graph of 128 vertices, 4 communities, like in
    Community Structure in  social and biological networks.
    <NAME>, 2002. PNAS June, vol 99 n 12

    Community is node modulo 4
    """

    pout = float(zout)/96.
    pin = (16.-pout*96.)/31.
    graph = nx.Graph()
    graph.add_nodes_from(range(128))
    for x in graph.nodes() :
        for y in graph.nodes() :
            if x < y :
                val = random.random()
                if x % 4 == y % 4 :
                    #nodes belong to the same community
                    if val < pin :
                        graph.add_edge(x, y)

                else :
                    if val < pout :
                        graph.add_edge(x, y)
    return graph


class InfomapTest(unittest.TestCase):

    def test_girvan(self):
        """
        Generate ground truth graph with 4 communities.
        Test that infomap detects them correctly
        """
        graph = girvan_graphs(4)
        modules = infomap.infomap(graph)

        for node, module in modules.items():
            self.assertEqual(module, modules[node%4])

    def test_nodes(self):
        """
        Test that the new graph generated in the the second phase has the communities as nodes
        """
        g = nx.erdos_renyi_graph(50, 0.1)
        part = dict([])
        for node in g.nodes() :
            part[node] = node % 5
        #set up mock object
        info_partition = infomap.Partition(g)
        info_partition.modules = part

        self.assertSetEqual(set(part.values()), set(info_partition.second_pass((info_partition.modules)).nodes()))


if __name__ == '__main__':
    unittest.main()<commit_msg>renaming and comment<commit_after>import unittest
import networkx as nx
import random

import infomap

def girvan_graphs(zout) :
    """
    Create a graph of 128 vertices, 4 communities, like in
    Community Structure in  social and biological networks.
    <NAME>, 2002. PNAS June, vol 99 n 12

    Community is node modulo 4
    """

    pout = float(zout)/96.
    pin = (16.-pout*96.)/31.
    graph = nx.Graph()
    graph.add_nodes_from(range(128))
    for x in graph.nodes() :
        for y in graph.nodes() :
            if x < y :
                val = random.random()
                if x % 4 == y % 4 :
                    #nodes belong to the same community
                    if val < pin :
                        graph.add_edge(x, y)

                else :
                    if val < pout :
                        graph.add_edge(x, y)
    return graph


class InfomapTest(unittest.TestCase):

    def test_girvan(self):
        """
        Generate ground truth graph with 4 communities.
        Test that infomap detects them correctly
        """
        graph = girvan_graphs(4)
        modules = infomap.infomap(graph)

        for node, module in modules.items():
            self.assertEqual(module, modules[node%4])

    def test_communites_to_nodes(self):
        """
        Test that the new graph generated in the the second phase has the number of communities as nodes
        """
        g = nx.erdos_renyi_graph(50, 0.1)
        partition = dict([])
        for node in g.nodes() :
            partition[node] = node % 5
        #set up mock object
        info_partition = infomap.Partition(g)
        info_partition.modules = partition

        self.assertSetEqual(set(partition.values()), set(info_partition.second_pass((info_partition.modules)).nodes()))


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.09479195370625516, 'fraction_numerical': 0.018737944337283, 'mean_word_length': 1.8560188827694728, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3387317', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1024, 'n_words': 319}