1
1
from unittest import TestCase , main
2
- from ShortestPath import ShortestPath
2
+ from ShortestPath import ShortestPath , Connection
3
3
4
4
from main import NODES , CONNECTIONS
5
5
@@ -11,14 +11,14 @@ def setUp(self):
11
11
12
12
def test_available_connections_in_a_node (self ):
13
13
node = 'a'
14
- expected = [{ 'dist' : 0 , 'nodes' : ['a' , 'a' ]} ,
15
- { 'dist' : 2 , 'nodes' : ['a' , 'b' ]} ,
16
- { 'dist' : 8 , 'nodes' : ['a' , 'd' ]} ]
14
+ expected = [Connection ( ['a' , 'a' ], 0 ) ,
15
+ Connection ( ['a' , 'b' ], 2 ) ,
16
+ Connection ( ['a' , 'd' ], 8 ) ]
17
17
self .assertEqual (expected , self .sp .available_connections (node ))
18
18
node = 'b'
19
- expected = [{ 'dist' : 2 , 'nodes' : ['a' , 'b' ]} ,
20
- { 'dist' : 5 , 'nodes' : ['b' , 'd' ]} ,
21
- { 'dist' : 6 , 'nodes' : ['b' , 'e' ]} ]
19
+ expected = [Connection ( ['a' , 'b' ], 2 ) ,
20
+ Connection ( ['b' , 'd' ], 5 ) ,
21
+ Connection ( ['b' , 'e' ], 6 ) ]
22
22
self .assertEqual (expected , self .sp .available_connections (node ))
23
23
24
24
def test_distance_from_x_to_y (self ):
@@ -32,22 +32,22 @@ def test_distance_from_x_to_y_that_dont_connects(self):
32
32
self .assertEqual (self .sp .distance ('a' , 'c' ), None )
33
33
34
34
def test_a_way_to_a_node (self ):
35
- expected = [[{ 'dist' : 2 , 'nodes' : ['a' , 'b' ]} ,
36
- { 'dist' : 6 , 'nodes' : ['b' , 'e' ]} ],
37
- [{ 'dist' : 8 , 'nodes' : ['a' , 'd' ]} ,
38
- { 'dist' : 3 , 'nodes' : ['d' , 'e' ]} ]]
35
+ expected = [[Connection ( ['a' , 'b' ], 2 ) ,
36
+ Connection ( ['b' , 'e' ], 6 ) ],
37
+ [Connection ( ['a' , 'd' ], 8 ) ,
38
+ Connection ( ['d' , 'e' ], 3 ) ]]
39
39
self .assertEqual (expected , self .sp .ways ('a' , 'e' ))
40
- expected = [[{ 'dist' : 6 , 'nodes' : ['b' , 'e' ]} ,
41
- { 'dist' : 9 , 'nodes' : ['c' , 'e' ]} ]]
40
+ expected = [[Connection ( ['b' , 'e' ], 6 ) ,
41
+ Connection ( ['c' , 'e' ], 9 ) ]]
42
42
self .assertEqual (expected , self .sp .ways ('b' , 'c' ))
43
43
44
44
def test_a_shortest_distance_in_ways (self ):
45
- ways = [[{ 'dist' : 2 , 'nodes' : ['a' , 'b' ]} ,
46
- { 'dist' : 6 , 'nodes' : ['b' , 'e' ]} ],
47
- [{ 'dist' : 8 , 'nodes' : ['a' , 'd' ]} ,
48
- { 'dist' : 3 , 'nodes' : ['d' , 'e' ]} ]]
49
- expected = [{ 'dist' : 2 , 'nodes' : ['a' , 'b' ]} ,
50
- { 'dist' : 6 , 'nodes' : ['b' , 'e' ]} ]
45
+ ways = [[Connection ( ['a' , 'b' ], 2 ) ,
46
+ Connection ( ['b' , 'e' ], 6 ) ],
47
+ [Connection ( ['a' , 'd' ], 8 ) ,
48
+ Connection ( ['d' , 'e' ], 3 ) ]]
49
+ expected = [Connection ( ['a' , 'b' ], 2 ) ,
50
+ Connection ( ['b' , 'e' ], 6 ) ]
51
51
self .assertEqual (expected , self .sp .shortest_way (ways ))
52
52
53
53
0 commit comments