-
Notifications
You must be signed in to change notification settings - Fork 14
/
postman_test.py
36 lines (26 loc) · 978 Bytes
/
postman_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python2.7
from __future__ import print_function
import unittest
import postman
class TestPostman(unittest.TestCase):
def setUp(self):
pass
# TODO: test the individual functions
def test_postman(self):
"""
Test the end result.
"""
with open('test_graph.csv', 'r') as csv:
graph = postman.import_csv_graph(csv)
components = postman.graph_components(graph)
# Only use the largest component
component = components[0]
eulerian_graph, nodes = postman.single_chinese_postman_path(component)
in_length = postman.edge_sum(graph) / 1000.0
path_length = postman.edge_sum(eulerian_graph) / 1000.0
duplicate_length = path_length - in_length
self.assertAlmostEqual(in_length, 14.889)
self.assertAlmostEqual(path_length, 20.316)
self.assertAlmostEqual(duplicate_length, 5.427)
if __name__ == '__main__':
unittest.main()