#!/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 copy
import random
import unittest

from lib import unigraph


def copy_graph(graph):
    return copy.deepcopy(graph)


class TestGraphCopy(unittest.TestCase):
    def setUp(self):
        self.graph = unigraph.Unigraph(random.randrange(10, 15))
        for x in range(2 * self.graph.vertices()):
            f, t = (random.randrange(0, self.graph.vertices())
                    for x in range(2))
            self.graph.add_edge(f, t)

    def test_copy_graph(self):
        graph_ = copy_graph(self.graph)
        self.assertEqual(str(graph_), str(self.graph))

    def test_independent_graph_copy(self):
        graph_ = copy_graph(self.graph)
        for i in range(5):
            f, t = (random.randrange(0, graph_.vertices()) for x in range(2))
            graph_.add_edge(f, t)

        self.assertNotEqual(str(graph_), str(self.graph))


if "__main__" == __name__:
    unittest.main()
