Test Failed
Pull Request — master (#68)
by Arturo
02:43
created

build.tests.integration.test_exactdelay_results   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TestExactDelayResults.test_edpf_can_show_best_path_first() 0 23 1
A TestExactDelayResults.test_edpf_can_show_empty_result() 0 19 1
A TestExactDelayResults.setUp() 0 3 1
1
"""Module to test the Pathfinder algorithm
2
performance with some constrains."""
3
4
from unittest import TestCase
5
from exactdelaypathfinder.core import ExactDelayPathfinder
6
import networkx as nx
7
8
9
class TestExactDelayResults(TestCase):
10
    """Tests for the Exact Delay result constrain."""
11
12
    def setUp(self):
13
        self.pathfinder = ExactDelayPathfinder()
14
        self.G = nx.Graph()
15
16
    def test_edpf_can_show_best_path_first(self):
17
        """Test search function to see if the first result is the best one."""
18
19
        # The following is a small-scale topology we will use to test the
20
        # algorithm's functionality and correctness. Modifying the nodes and edges (links)
21
        # of the graph (topology) will affect the outcome of the test which may result in a failure.
22
        nodes = ['User1', 'S2', 'S3', 'S4', 'S5', 'S6', 'User2']
23
        self.G.add_nodes_from(nodes)
24
        edges = [('User1', 'S2', {'delay': 10}), ('User1', 'S3', {'delay': 37}),
25
                 ('S2', 'S4', {'delay': 24}), ('S3', 'S4', {'delay': 48}),
26
                 ('S3', 'S6', {'delay': 96}), ('S4', 'S5', {'delay': 1}),
27
                 ('S6', 'User2', {'delay': 84}), ('S5', 'User2', {'delay': 29})]
28
29
        self.G.add_edges_from(edges)
30
31
        # Create result variables and run the test search
32
        result = []
33
        result = self.pathfinder.search(self.G, 64, 'User1', 'User2')
34
        first_result = result[0]
35
        actual = first_result.get('total_delay')  # extract first result
36
37
        # The first result should be an exact path with delay of 64
38
        self.assertEqual(64, actual)
39
40
    def test_edpf_can_show_empty_result(self):
41
        """Test search function to see if it can return an empty result."""
42
43
        edges = [('User1', 'S2', {'delay': 10}), ('User1', 'S3', {'delay': 37}),
44
                 ('S2', 'S4', {'delay': 24}), ('S3', 'S4', {'delay': 48}),
45
                 ('S3', 'S6', {'delay': 96}), ('S4', 'S5', {'delay': 1}),
46
                 ('S6', 'User2', {'delay': 84}), ('S5', 'User2', {'delay': 29})]
47
48
        self.G.add_edges_from(edges)
49
50
        # Create isolated node. This node is not connected to another node.
51
        isolated_nodes = ['S7']
52
        self.G.add_nodes_from(isolated_nodes)
53
54
        result = []
55
56
        # Find path to the unreachable node - impossible
57
        result = self.pathfinder.search(self.G, 64, 'User1', 'S7')
58
        self.assertEqual([], result)
59