Advertisement
tomasfdel

Complementos I Práctica Lab 3 Test

Sep 12th, 2017
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.99 KB | None | 0 0
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import unittest
  5.  
  6. from practica_3 import (check_is_hamiltonian_trail,
  7.                         check_is_hamiltonian_circuit,
  8.                         check_is_eulerian_trail,
  9.                         check_is_eulerian_circuit,
  10.                         graph_has_eulerian_circuit,
  11.                         find_eulerian_circuit)
  12.  
  13.  
  14. class TestIsHamiltoneanTrail(unittest.TestCase):
  15.     graph_1 = ([], [])
  16.     graph_2 = (['a'], [])
  17.     graph_3 = (['a'], [('a', 'a')])
  18.     graph_4 = (['a', 'b'], [('a', 'b')])
  19.     graph_5 = (['a', 'b', 'c'], [('a', 'b'), ('b', 'c')])
  20.     graph_6 = (['a', 'b', 'c', 'd'],
  21.                [('a', 'b'), ('b', 'c'), ('a', 'd'), ('c', 'd'), ('d', 'a')])
  22.  
  23.     is_trail_cases = [
  24.         (graph_1, []),
  25.         (graph_4, [('a', 'b')]),
  26.         (graph_5, [('a', 'b'), ('b', 'c')]),
  27.         (graph_6, [('a', 'b'), ('b', 'c'), ('c', 'd')])
  28.     ]
  29.  
  30.     is_not_trail_cases = [
  31.         (graph_1, [('a', 'b')]),
  32.         (graph_2, [('b', 'a')]),
  33.         (graph_2, []),
  34.         (graph_3, [('b', 'a')]),
  35.         (graph_3, []),
  36.         (graph_4, []),
  37.         (graph_4, [('a', 'c'), ('c', 'b')]),
  38.         (graph_5, [('b', 'c'), ('a', 'b')]),
  39.         (graph_6, [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'a')])
  40.     ]
  41.  
  42.     def test_is_trail_cases(self):
  43.         for graph, path in self.is_trail_cases:
  44.             result = check_is_hamiltonian_trail(graph, path)
  45.             self.assertTrue(
  46.                 result,
  47.                 'caso: check_is_hamiltonian_trail({}, {})'.format(graph, path)
  48.             )
  49.  
  50.     def test_is_not_trail_cases(self):
  51.         for graph, path in self.is_not_trail_cases:
  52.             result = check_is_hamiltonian_trail(graph, path)
  53.             self.assertFalse(
  54.                 result,
  55.                 'caso: check_is_hamiltonian_trail({}, {})'.format(graph, path)
  56.             )
  57.  
  58.            
  59. class TestIsHamiltoneanCircuit(unittest.TestCase):
  60.     graph_1 = ([], [])
  61.     graph_2 = (['a'], [])
  62.     graph_3 = (['a'], [('a', 'a')])
  63.     graph_4 = (['a', 'b'], [('a', 'b'), ('b', 'a')])
  64.     graph_5 = (['a', 'b', 'c'], [('a', 'b'), ('b', 'c')])
  65.     graph_6 = (['a', 'b', 'c', 'd'],
  66.                [('a', 'b'), ('b', 'c'), ('a', 'd'), ('c', 'd'), ('d', 'a')])
  67.  
  68.     is_circuit_cases = [
  69.         (graph_1, []),
  70.         (graph_3, [('a', 'a')]),
  71.         (graph_4, [('a', 'b'), ('b', 'a')]),
  72.         (graph_6, [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'a')])
  73.     ]
  74.  
  75.     is_not_circuit_cases = [
  76.         (graph_1, [('a', 'b')]),
  77.         (graph_2, [('b', 'a')]),
  78.         (graph_2, []),
  79.         (graph_3, [('b', 'a')]),
  80.         (graph_3, []),
  81.         (graph_4, []),
  82.         (graph_4, [('a', 'c'), ('c', 'a')]),
  83.         (graph_5, [('b', 'c'), ('a', 'b')]),
  84.         (graph_6, [('a', 'b'), ('b', 'c'), ('c', 'd')])
  85.     ]
  86.  
  87.     def test_is_circuit_cases(self):
  88.         for graph, path in self.is_circuit_cases:
  89.             result = check_is_hamiltonian_circuit(graph, path)
  90.             self.assertTrue(
  91.                 result,
  92.                 'caso: check_is_hamiltonian_circuit({}, {})'.format(graph, path)
  93.             )
  94.  
  95.     def test_is_not_circuit_cases(self):
  96.         for graph, path in self.is_not_circuit_cases:
  97.             result = check_is_hamiltonian_circuit(graph, path)
  98.             self.assertFalse(
  99.                 result,
  100.                 'caso: check_is_hamiltonian_circuit({}, {})'.format(graph, path)
  101.             )
  102.  
  103.  
  104. class TestIsEulerianTrail(unittest.TestCase):
  105.     graph_1 = ([], [])
  106.     graph_2 = (['a'], [])
  107.     graph_3 = (['a'], [('a', 'a')])
  108.     graph_4 = (['a', 'b'], [('a', 'b')])
  109.     graph_5 = (['a', 'b', 'c'], [('a', 'b'), ('b', 'c')])
  110.     graph_6 = (['a', 'b', 'c', 'd'],
  111.                [('a', 'b'), ('b', 'c'), ('a', 'd'), ('c', 'd'), ('d', 'a')])
  112.     graph_7 = (['a', 'b', 'c', 'd'],
  113.                 [('a','b'),('b','c'),('c','a')])
  114.  
  115.     is_trail_cases = [
  116.         (graph_1, []),
  117.         (graph_3, [('a','a')]),
  118.         (graph_4, [('a', 'b')]),
  119.         (graph_5, [('a', 'b'), ('b', 'c')]),
  120.         (graph_6, [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d','a'), ('a', 'd')])
  121.     ]
  122.  
  123.     is_not_trail_cases = [
  124.         (graph_1, [('a', 'b')]),
  125.         (graph_2, [('b', 'a')]),
  126.         (graph_2, []),
  127.         (graph_3, [('b', 'a')]),
  128.         (graph_3, []),
  129.         (graph_4, []),
  130.         (graph_4, [('a', 'c'), ('c', 'b')]),
  131.         (graph_5, [('b', 'c'), ('a', 'b')]),
  132.         (graph_6, [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'a')]),
  133.         (graph_7, [('a','b'),('b','c'),('c','a')])
  134.     ]
  135.  
  136.     def test_is_trail_cases(self):
  137.         for graph, path in self.is_trail_cases:
  138.             result = check_is_eulerian_trail(graph, path)
  139.             self.assertTrue(
  140.                 result,
  141.                 'caso: check_is_eulerian_trail({}, {})'.format(graph, path)
  142.             )
  143.  
  144.     def test_is_not_trail_cases(self):
  145.         for graph, path in self.is_not_trail_cases:
  146.             result = check_is_eulerian_trail(graph, path)
  147.             self.assertFalse(
  148.                 result,
  149.                 'caso: check_is_eulerian_trail({}, {})'.format(graph, path)
  150.             )
  151.  
  152.  
  153. class TestIsEulerianCircuit(unittest.TestCase):
  154.     graph_1 = ([], [])
  155.     graph_2 = (['a'], [])
  156.     graph_3 = (['a'], [('a', 'a')])
  157.     graph_4 = (['a', 'b'], [('a', 'b')])
  158.     graph_5 = (['a', 'b', 'c'], [('a', 'b'), ('b', 'c')])
  159.     graph_6 = (['a', 'b', 'c', 'd'],
  160.                [('a', 'b'), ('b', 'c'), ('a', 'd'), ('c', 'd'), ('d', 'a'),('b','a'),('d','b')])
  161.     graph_7 = (['a', 'b', 'c', 'd'],
  162.                 [('a','b'),('b','c'),('c','a')])
  163.  
  164.     is_circuit_cases = [
  165.         (graph_1, []),
  166.         (graph_3, [('a','a')]),
  167.         (graph_6, [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d','a'), ('a', 'd'),('d','b'),('b','a')])
  168.     ]
  169.  
  170.     is_not_circuit_cases = [
  171.         (graph_1, [('a', 'b')]),
  172.         (graph_2, [('b', 'a')]),
  173.         (graph_2, []),
  174.         (graph_3, [('b', 'a')]),
  175.         (graph_3, []),
  176.         (graph_4, []),
  177.         (graph_4, [('a', 'c'), ('c', 'b')]),
  178.         (graph_4, [('a', 'b')]),
  179.         (graph_5, [('a', 'b'), ('b', 'c')]),
  180.         (graph_5, [('b', 'c'), ('a', 'b')]),
  181.         (graph_6, [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'a')]),
  182.         (graph_7, [('a','b'),('b','c'),('c','a')])
  183.     ]
  184.  
  185.     def test_is_circuit_cases(self):
  186.         for graph, path in self.is_circuit_cases:
  187.             result = check_is_eulerian_circuit(graph, path)
  188.             self.assertTrue(
  189.                 result,
  190.                 'caso: check_is_eulerian_circuit({}, {})'.format(graph, path)
  191.             )
  192.  
  193.     def test_is_not_circuit_cases(self):
  194.         for graph, path in self.is_not_circuit_cases:
  195.             result = check_is_eulerian_circuit(graph, path)
  196.             self.assertFalse(
  197.                 result,
  198.                 'caso: check_is_eulerian_circuit{}, {})'.format(graph, path)
  199.             )
  200.  
  201.  
  202.  
  203.  
  204. class TestHasEulerianCircuit(unittest.TestCase):
  205.     pass
  206.  
  207.  
  208. class TestFindEulerianCircuit(unittest.TestCase):
  209.     pass
  210.  
  211. if __name__ == '__main__':
  212.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement