<|file_name|>ch4_ex4.1.4.py<|end_file_name|><｜fim▁begin｜>#!/usr/bin/env python
#
# Created by Samvel Khalatyan on Mar 23, 2014
# Copyright (c) 2014 Samvel Khalatyan. All rights reserved
#
# Use of this source code is governed by a license that can be found in
# the LICENSE file.

import random
import unittest

from lib import unigraph


class UnigraphExtra(unigraph.Unigraph):
    def has_edge(self, left_vertex, right_vertex):
        if left_vertex == right_vertex:
            return True
        else:
            return right_vertex in self._vertices[left_vertex]


class UnigraphEdgeTestCase(unittest.TestCase):
    def setUp(self):
        self.graph = UnigraphExtra(random.randrange(10, 15))
        for edge in range(2 * self.graph.vertices()):
            f, t = (random.randrange(self.graph.vertices()) for x in range(2))
            self.graph.add_edge(f, t)

    def test_edge(self):
        for vertex in range(self.graph.vertices()):
            existing_vertices = set(self.graph._vertices[vertex])
            all_vertices = set(range(self.graph.vertices()))

            missing_vertices = all_vertices - all_vertices
            for adj_vertex in existing_vertices:
                self.assertTrue(self.graph.has_edge(vertex, adj_vertex))

            for adj_vertex in missing_vertices:
                self.assertFalse(self.graph.has_edge(vertex, adj_vertex))

    def test_self_loop(self):
        <|fim_middle|>



if "__main__" == __name__:
    unittest.main()
<｜fim▁end｜>
        for vertex in range(self.graph.vertices()):
            self.assertTrue(self.graph.has_edge(vertex, vertex))