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 add_edges(self): |
17
|
|
|
edges = [('User1', 'S2', {'delay': 10}), ('User1', 'S3', {'delay': 37}), |
18
|
|
|
('S2', 'S4', {'delay': 24}), ('S3', 'S4', {'delay': 48}), |
19
|
|
|
('S3', 'S6', {'delay': 96}), ('S4', 'S5', {'delay': 1}), |
20
|
|
|
('S6', 'User2', {'delay': 84}), ('S5', 'User2', {'delay': 29})] |
21
|
|
|
self.G.add_edges_from(edges) |
22
|
|
|
|
23
|
|
|
def test_edpf_can_show_best_path_first(self): |
24
|
|
|
"""Test search function to see if the first result is the best one.""" |
25
|
|
|
|
26
|
|
|
# The following is a small-scale topology we will use to test the |
27
|
|
|
# algorithm's functionality and correctness. Modifying the nodes and edges (links) |
28
|
|
|
# of the graph (topology) will affect the outcome of the test which may result in a failure. |
29
|
|
|
nodes = ['User1', 'S2', 'S3', 'S4', 'S5', 'S6', 'User2'] |
30
|
|
|
self.G.add_nodes_from(nodes) |
31
|
|
|
self.add_edges() |
32
|
|
|
|
33
|
|
|
# Create result variables and run the test search |
34
|
|
|
result = self.pathfinder.search(self.G, 64, 'User1', 'User2') |
35
|
|
|
first_result = result[0] |
36
|
|
|
actual = first_result.get('total_delay') # extract first result |
37
|
|
|
|
38
|
|
|
# The first result should be an exact path with delay of 64 |
39
|
|
|
self.assertEqual(64, actual) |
40
|
|
|
|
41
|
|
|
def test_edpf_can_show_empty_result(self): |
42
|
|
|
"""Test search function to see if it can return an empty result.""" |
43
|
|
|
self.add_edges() |
44
|
|
|
|
45
|
|
|
# Create isolated node. This node is not connected to another node. |
46
|
|
|
isolated_nodes = ['S7'] |
47
|
|
|
self.G.add_nodes_from(isolated_nodes) |
48
|
|
|
|
49
|
|
|
# Find path to the unreachable node - impossible |
50
|
|
|
result = self.pathfinder.search(self.G, 64, 'User1', 'S7') |
51
|
|
|
self.assertEqual([], result) |
52
|
|
|
|