<commit_before># -*- coding: utf-8 -*-
"""Simple Graph structure."""


class SimpleGraph(object):
    """Defining simple graph class."""

    def _reset(self):
        self.graph_dict = {}

    def __init__(self):
        """Initialize Simple Graph object."""
        self._reset()

    def nodes(self):
        """Return a list of all nodes in the dict."""
        node_list = list(self.graph_dict.keys())
        return node_list

    def edges(self):
        """Return a list of all edges in the dict."""
        to_return = []
        for key in list(self.graph_dict.keys()):
            for value in self.graph_dict.get(key):
                to_return.append('{}-{}'.format(key, value))
        return to_return

    def add_node(self, node):
        """Add a new node 'n' to the graph."""
        self.graph_dict.setdefault(node, [])

    def add_edge(self, node1, node2):
        """Add a edge from node 1 to node 2."""
        self.add_node(node1)
        self.add_node(node2)
        self.graph_dict[node1].append(node2)

    def del_node(self, node):
        """Delete the node from the graph."""
        try:
            del self.graph_dict[node]
            for key in self.graph_dict:
                if node in self.graph_dict[key]:
                    self.graph_dict[key].remove(node)
        except KeyError:
            raise KeyError('Node does not exist')

    def del_edge(self, node1, node2):
        """Delete the edge connecting node 1 and node 2."""
        try:
            self.graph_dict[node1].remove(node2)
        except KeyError:
            raise KeyError('Node1 does not exist')
        except ValueError:
            raise ValueError('Node2 does not exist')

    def has_node(self, node):
        """Return a boolean for if node exists."""
        return isinstance(self.graph_dict.get(node), list)

    def neighbors(self, node):
        """Return the list of all nodes connected to by edges."""
        return self.graph_dict.get(node)

    def adjacent(self, node1, node2):
        """Return boolean for edges between two nodes."""
        try:
            return node2 in self.graph_dict.get(node1)
        except TypeError:
            return False

    def depth_first_traversal(self, start):
        pass

    def breadth_first_traversal(self, starting_node):
        try:
            to_search = [starting_node] + self.graph_dict[starting_node]
        except KeyError:
            raise ValueError("Node does not exist")
        copy = None
        while copy != to_search:
            copy = to_search[:]
            for item in to_search:
                for sub_item in copy[item]:
                    if sub_item not in copy:
                        copy.append(sub_item)
            to_search = copy[:]<commit_msg>set up main for testing<commit_after># -*- coding: utf-8 -*-
"""Simple Graph structure."""


class SimpleGraph(object):
    """Defining simple graph class."""

    def _reset(self):
        self.graph_dict = {}

    def __init__(self):
        """Initialize Simple Graph object."""
        self._reset()

    def nodes(self):
        """Return a list of all nodes in the dict."""
        node_list = list(self.graph_dict.keys())
        return node_list

    def edges(self):
        """Return a list of all edges in the dict."""
        to_return = []
        for key in list(self.graph_dict.keys()):
            for value in self.graph_dict.get(key):
                to_return.append('{}-{}'.format(key, value))
        return to_return

    def add_node(self, node):
        """Add a new node 'n' to the graph."""
        self.graph_dict.setdefault(node, [])

    def add_edge(self, node1, node2):
        """Add a edge from node 1 to node 2."""
        self.add_node(node1)
        self.add_node(node2)
        self.graph_dict[node1].append(node2)

    def del_node(self, node):
        """Delete the node from the graph."""
        try:
            del self.graph_dict[node]
            for key in self.graph_dict:
                if node in self.graph_dict[key]:
                    self.graph_dict[key].remove(node)
        except KeyError:
            raise KeyError('Node does not exist')

    def del_edge(self, node1, node2):
        """Delete the edge connecting node 1 and node 2."""
        try:
            self.graph_dict[node1].remove(node2)
        except KeyError:
            raise KeyError('Node1 does not exist')
        except ValueError:
            raise ValueError('Node2 does not exist')

    def has_node(self, node):
        """Return a boolean for if node exists."""
        return isinstance(self.graph_dict.get(node), list)

    def neighbors(self, node):
        """Return the list of all nodes connected to by edges."""
        return self.graph_dict.get(node)

    def adjacent(self, node1, node2):
        """Return boolean for edges between two nodes."""
        try:
            return node2 in self.graph_dict.get(node1)
        except TypeError:
            return False

    def depth_first_traversal(self, start):
        pass

    def breadth_first_traversal(self, starting_node):
        import pdb; pdb.set_trace()
        try:
            to_search = [starting_node] + self.graph_dict[starting_node]
        except KeyError:
            raise ValueError("Node does not exist")
        copy = None
        while copy != to_search:
            copy = to_search[:]
            for item in to_search:
                for sub_item in copy[item]:
                    if sub_item not in copy:
                        copy.append(sub_item)
            to_search = copy[:]

if __name__ == '__main__':
    obj = SimpleGraph()
    obj.add_node('A')
    obj.add_node('B')
    obj.add_node('C')
    obj.add_node('D')
    obj.add_node('E')
    obj.add_node('F')
    obj.add_node('G')
    obj.add_edge('A', 'B')
    obj.add_edge('A', 'C')
    obj.add_edge('A', 'D')
    obj.add_edge('C', 'E')
    obj.add_edge('C', 'F')
    obj.add_edge('D', 'G')
    obj.breadth_first_traversal('A')

{'fraction_non_alphanumeric': 0.11776513884242222, 'fraction_numerical': 0.00702576112412178, 'mean_word_length': 2.0258097165991904, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2839306', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1722, 'n_words': 501}