Ejemplo n.º 1
0
 def test_all(self):
     for spec in [
         dict(input=in1, output=out1),
         # dict(input=in2, output=out2),
     ]:
         actual = number_of_components(parse_input(spec['input']))
         expected = spec['output']
         self.assertEqual(actual, expected)
Ejemplo n.º 2
0
 def test_5(self):
     self.assertEqual(
         number_of_components({
             1: [2],
             3: [2],
             4: [],
             2: [1, 3]
         }), 2)
Ejemplo n.º 3
0
 def test_2(self):
     self.assertEqual(
         number_of_components({
             1: [2],
             2: [1, 3],
             3: [2],
             4: [5],
             5: [4]
         }), 2)
Ejemplo n.º 4
0
    def test_generated_graphs(self):
        print("\n")
        for i in range(100):
            has_path = random.choice([True, False])
            num_v, edges, expected = gen_graph()
            print("graph {:03} (num_components= {:4}, num_v = {:4}, num_e = {:7}) ... ".format(i, expected, num_v, len(edges))), 
            generated_input = graph_to_string(num_v, edges)
            # print(generated_input)
            adj = parse_input(generated_input)
            t_before = time.time()
            actual = number_of_components(adj)
            duration = time.time() - t_before
            print("\tduration = {}".format(duration))

            self.assertEqual(actual, expected)
Ejemplo n.º 5
0
 def test1(self):
     result = connected_components.number_of_components([[1, 3], [0, 2],
                                                         [1, 3], [2, 0]])
     self.assertEqual(1, result)
Ejemplo n.º 6
0
 def test2(self):
     result = connected_components.number_of_components([[1], [0], [3],
                                                         [2]])
     self.assertEqual(2, result)
Ejemplo n.º 7
0
 def test_1(self):
     self.assertEqual(number_of_components({1: [2], 2: [1, 3], 3: [2]}), 1)
Ejemplo n.º 8
0
 def test_4(self):
     self.assertEqual(number_of_components({1: []}), 1)
Ejemplo n.º 9
0
def test_number_of_components(g1, g2):
    assert number_of_components(g1) == 1
    assert number_of_components(g2) == 2