@@ -16,18 +16,18 @@ importall MetaGraphs
16
16
dgx = PathDiGraph (4 )
17
17
18
18
mg = MetaGraph ()
19
- @test add_vertex! (mg,:color ," red" ) && get_prop (mg,nv (mg),:color ) == " red"
20
- @test add_vertex! (mg,Dict (:color => " red" ,:prop2 => " prop2" )) && props (mg,nv (mg)) == Dict (:color => " red" ,:prop2 => " prop2" )
21
- @test add_edge! (mg,1 , 2 , :color ," blue" ) && get_prop (mg,1 , 2 , :color ) == " blue"
22
- @test add_vertex! (mg) && add_edge! (mg,1 , 3 , Dict (:color => " red" ,:prop2 => " prop2" )) && props (mg,1 , 3 ) == Dict (:color => " red" ,:prop2 => " prop2" )
19
+ @test add_vertex! (mg, :color , " red" ) && get_prop (mg, nv (mg), :color ) == " red"
20
+ @test add_vertex! (mg, Dict (:color => " red" , :prop2 => " prop2" )) && props (mg, nv (mg)) == Dict (:color => " red" , :prop2 => " prop2" )
21
+ @test add_edge! (mg, 1 , 2 , :color , " blue" ) && get_prop (mg, 1 , 2 , :color ) == " blue"
22
+ @test add_vertex! (mg) && add_edge! (mg, 1 , 3 , Dict (:color => " red" , :prop2 => " prop2" )) && props (mg, 1 , 3 ) == Dict (:color => " red" , :prop2 => " prop2" )
23
23
24
24
for g in testgraphs (gx)
25
25
mg = MetaGraph (g)
26
26
g2 = SimpleGraph (mg)
27
27
@test g2 == mg. graph
28
28
29
- @test eltype (@inferred (MetaGraph {UInt8, Float16} (mg))) == UInt8
30
- @test weighttype (@inferred (MetaGraph {UInt8, Float16} (mg))) == Float16
29
+ @test eltype (@inferred (MetaGraph {UInt8,Float16} (mg))) == UInt8
30
+ @test weighttype (@inferred (MetaGraph {UInt8,Float16} (mg))) == Float16
31
31
32
32
@test @inferred (MetaGraphs. fadj (mg, 2 )) == LightGraphs. SimpleGraphs. fadj (g, 2 )
33
33
@test @inferred (MetaGraphs. badj (mg, 2 )) == LightGraphs. SimpleGraphs. badj (g, 2 )
@@ -38,22 +38,22 @@ importall MetaGraphs
38
38
@test @inferred (eltype (MetaGraph (g, 2.0 ))) == eltype (g)
39
39
@test @inferred (eltype (MetaGraph (g, :cost ))) == eltype (g)
40
40
@test @inferred (eltype (MetaGraph (g, :cost , 2.0 ))) == eltype (g)
41
- @test @inferred (eltype (MetaGraph {UInt8, Float16} (g))) == UInt8
42
- @test @inferred (eltype (MetaGraph {UInt8, Float16} (g, :cost ))) == UInt8
43
- @test @inferred (eltype (MetaGraph {UInt8, Float16} (g, 4 ))) == UInt8
41
+ @test @inferred (eltype (MetaGraph {UInt8,Float16} (g))) == UInt8
42
+ @test @inferred (eltype (MetaGraph {UInt8,Float16} (g, :cost ))) == UInt8
43
+ @test @inferred (eltype (MetaGraph {UInt8,Float16} (g, 4 ))) == UInt8
44
44
@test @inferred (ne (mg)) == 3
45
45
@test @inferred (nv (mg)) == 4
46
46
@test @inferred (! is_directed (mg))
47
47
48
48
@test @inferred (vertices (mg)) == 1 : 4
49
- @test Edge (2 ,3 ) in edges (mg)
50
- @test @inferred (outneighbors (mg,2 )) == inneighbors (mg,2 ) == neighbors (mg,2 )
49
+ @test Edge (2 , 3 ) in edges (mg)
50
+ @test @inferred (outneighbors (mg, 2 )) == inneighbors (mg, 2 ) == neighbors (mg, 2 )
51
51
@test @inferred (has_edge (mg, 2 , 3 ))
52
52
@test @inferred (has_edge (mg, 3 , 2 ))
53
53
54
54
mgc = copy (mg)
55
- @test @inferred (add_edge! (mgc, 4 => 1 )) && mgc == MetaGraph (CycleGraph (4 ))
56
- @test @inferred (has_edge (mgc, 4 => 1 )) && has_edge (mgc, 0x04 => 0x01 )
55
+ @test @inferred (add_edge! (mgc, 4 => 1 )) && mgc == MetaGraph (CycleGraph (4 ))
56
+ @test @inferred (has_edge (mgc, 4 => 1 )) && has_edge (mgc, 0x04 => 0x01 )
57
57
mgc = copy (mg)
58
58
@test @inferred (add_edge! (mgc, (4 , 1 ))) && mgc == MetaGraph (CycleGraph (4 ))
59
59
@test @inferred (has_edge (mgc, (4 , 1 ))) && has_edge (mgc, (0x04 , 0x01 ))
@@ -69,11 +69,11 @@ importall MetaGraphs
69
69
@test @inferred (rem_vertex! (mga, 2 )) && ne (mga) == 1
70
70
@test @inferred (! rem_vertex! (mga, 10 ))
71
71
72
- @test @inferred (zero (mg)) == MetaGraph {eltype(mg), weighttype(mg)} ()
72
+ @test @inferred (zero (mg)) == MetaGraph {eltype(mg),weighttype(mg)} ()
73
73
@test @inferred (eltype (mg)) == eltype (outneighbors (mg, 1 )) == eltype (nv (mg))
74
74
T = @inferred (eltype (mg))
75
75
U = @inferred (weighttype (mg))
76
- @test @inferred (nv (MetaGraph {T, U} (6 ))) == 6
76
+ @test @inferred (nv (MetaGraph {T,U} (6 ))) == 6
77
77
78
78
end
79
79
@@ -82,8 +82,8 @@ importall MetaGraphs
82
82
g2 = SimpleDiGraph (mg)
83
83
@test g2 == mg. graph
84
84
85
- @test eltype (@inferred (MetaDiGraph {UInt8, Float16} (mg))) == UInt8
86
- @test weighttype (@inferred (MetaDiGraph {UInt8, Float16} (mg))) == Float16
85
+ @test eltype (@inferred (MetaDiGraph {UInt8,Float16} (mg))) == UInt8
86
+ @test weighttype (@inferred (MetaDiGraph {UInt8,Float16} (mg))) == Float16
87
87
88
88
@test @inferred (MetaGraphs. fadj (mg, 2 )) == LightGraphs. SimpleGraphs. fadj (g, 2 )
89
89
@test @inferred (MetaGraphs. badj (mg, 2 )) == LightGraphs. SimpleGraphs. badj (g, 2 )
@@ -94,24 +94,24 @@ importall MetaGraphs
94
94
@test @inferred (eltype (MetaDiGraph (g, 2.0 ))) == eltype (g)
95
95
@test @inferred (eltype (MetaDiGraph (g, :cost ))) == eltype (g)
96
96
@test @inferred (eltype (MetaDiGraph (g, :cost , 2.0 ))) == eltype (g)
97
- @test @inferred (eltype (MetaDiGraph {UInt8, Float16} (g))) == UInt8
98
- @test @inferred (eltype (MetaDiGraph {UInt8, Float16} (g, :cost ))) == UInt8
99
- @test @inferred (eltype (MetaDiGraph {UInt8, Float16} (g, 4 ))) == UInt8
97
+ @test @inferred (eltype (MetaDiGraph {UInt8,Float16} (g))) == UInt8
98
+ @test @inferred (eltype (MetaDiGraph {UInt8,Float16} (g, :cost ))) == UInt8
99
+ @test @inferred (eltype (MetaDiGraph {UInt8,Float16} (g, 4 ))) == UInt8
100
100
101
101
@test @inferred (ne (mg)) == 3
102
102
@test @inferred (nv (mg)) == 4
103
103
@test @inferred (is_directed (mg))
104
104
105
105
@test @inferred (vertices (mg)) == 1 : 4
106
- @test Edge (2 ,3 ) in edges (mg)
107
- @test @inferred (outneighbors (mg,2 )) == [3 ]
108
- @test @inferred (inneighbors (mg,2 )) == [1 ]
106
+ @test Edge (2 , 3 ) in edges (mg)
107
+ @test @inferred (outneighbors (mg, 2 )) == [3 ]
108
+ @test @inferred (inneighbors (mg, 2 )) == [1 ]
109
109
@test @inferred (has_edge (mg, 2 , 3 ))
110
110
@test @inferred (! has_edge (mg, 3 , 2 ))
111
111
112
112
mgc = copy (mg)
113
- @test @inferred (add_edge! (mgc, 4 => 1 )) && mgc == MetaDiGraph (CycleDiGraph (4 ))
114
- @test @inferred (has_edge (mgc, 4 => 1 )) && has_edge (mgc, 0x04 => 0x01 )
113
+ @test @inferred (add_edge! (mgc, 4 => 1 )) && mgc == MetaDiGraph (CycleDiGraph (4 ))
114
+ @test @inferred (has_edge (mgc, 4 => 1 )) && has_edge (mgc, 0x04 => 0x01 )
115
115
mgc = copy (mg)
116
116
@test @inferred (add_edge! (mgc, (4 , 1 ))) && mgc == MetaDiGraph (CycleDiGraph (4 ))
117
117
@test @inferred (has_edge (mgc, (4 , 1 ))) && has_edge (mgc, (0x04 , 0x01 ))
@@ -127,11 +127,11 @@ importall MetaGraphs
127
127
@test @inferred (rem_vertex! (mga, 2 )) && ne (mga) == 1
128
128
@test @inferred (! rem_vertex! (mga, 10 ))
129
129
130
- @test @inferred (zero (mg)) == MetaDiGraph {eltype(mg), weighttype(mg)} ()
130
+ @test @inferred (zero (mg)) == MetaDiGraph {eltype(mg),weighttype(mg)} ()
131
131
@test @inferred (eltype (mg)) == eltype (outneighbors (mg, 1 )) == eltype (nv (mg))
132
132
T = @inferred (eltype (mg))
133
133
U = @inferred (weighttype (mg))
134
- @test @inferred (nv (MetaDiGraph {T, U} (6 ))) == 6
134
+ @test @inferred (nv (MetaDiGraph {T,U} (6 ))) == 6
135
135
end
136
136
137
137
for gbig in [SimpleGraph (0xff ), SimpleDiGraph (0xff )]
@@ -161,13 +161,13 @@ importall MetaGraphs
161
161
162
162
mg = MetaGraph (CompleteGraph (3 ), 3.0 )
163
163
@test enumerate_paths (dijkstra_shortest_paths (mg, 1 ), 3 ) == [1 , 3 ]
164
- @test typeof (set_prop! (mg, 1 , 2 , :weight , 0.2 )) == Dict{Symbol, Float64}
165
- @test typeof (set_prop! (mg, 2 , 3 , :weight , 1 )) == Dict{Symbol, Int64}
164
+ @test typeof (set_prop! (mg, 1 , 2 , :weight , 0.2 )) == Dict{Symbol,Float64}
165
+ @test typeof (set_prop! (mg, 2 , 3 , :weight , 1 )) == Dict{Symbol,Int64}
166
166
@test enumerate_paths (dijkstra_shortest_paths (mg, 1 ), 3 ) == [1 , 2 , 3 ]
167
167
168
- @test typeof (set_prop! (mg, 1 , :color , " blue" )) == Dict{Symbol, String}
169
- @test typeof (set_prop! (mg, 1 , :id , 0x5 )) == Dict{Symbol, Any}
170
- @test typeof (set_prop! (mg, :name , " test graph" )) == Dict{Symbol, Any}
168
+ @test typeof (set_prop! (mg, 1 , :color , " blue" )) == Dict{Symbol,String}
169
+ @test typeof (set_prop! (mg, 1 , :id , 0x5 )) == Dict{Symbol,Any}
170
+ @test typeof (set_prop! (mg, :name , " test graph" )) == Dict{Symbol,Any}
171
171
172
172
173
173
@test length (props (mg)) == 1
@@ -198,13 +198,13 @@ importall MetaGraphs
198
198
mg = MetaDiGraph (PathDiGraph (3 ), 3.0 )
199
199
add_edge! (mg, 1 , 3 )
200
200
@test enumerate_paths (dijkstra_shortest_paths (mg, 1 ), 3 ) == [1 , 3 ]
201
- @test typeof (set_prop! (mg, 1 , 2 , :weight , 0.2 )) == Dict{Symbol, Float64}
202
- @test typeof (set_prop! (mg, 2 , 3 , :weight , 1 )) == Dict{Symbol, Int64}
201
+ @test typeof (set_prop! (mg, 1 , 2 , :weight , 0.2 )) == Dict{Symbol,Float64}
202
+ @test typeof (set_prop! (mg, 2 , 3 , :weight , 1 )) == Dict{Symbol,Int64}
203
203
@test enumerate_paths (dijkstra_shortest_paths (mg, 1 ), 3 ) == [1 , 2 , 3 ]
204
204
205
- @test typeof (set_prop! (mg, 1 , :color , " blue" )) == Dict{Symbol, String}
206
- @test typeof (set_prop! (mg, 1 , :id , 0x5 )) == Dict{Symbol, Any}
207
- @test typeof (set_prop! (mg, :name , " test graph" )) == Dict{Symbol, Any}
205
+ @test typeof (set_prop! (mg, 1 , :color , " blue" )) == Dict{Symbol,String}
206
+ @test typeof (set_prop! (mg, 1 , :id , 0x5 )) == Dict{Symbol,Any}
207
+ @test typeof (set_prop! (mg, :name , " test graph" )) == Dict{Symbol,Any}
208
208
209
209
210
210
@test length (props (mg)) == 1
@@ -249,10 +249,10 @@ importall MetaGraphs
249
249
@test weightfield! (mg, :weight ) == :weight
250
250
@test enumerate_paths (dijkstra_shortest_paths (mg, 1 ), 3 ) == [1 , 2 , 3 ]
251
251
252
- @test length (set_props! (mg, 1 , 2 , Dict (:color => :blue , :action => " knows" ))) == 3
252
+ @test length (set_props! (mg, 1 , 2 , Dict (:color => :blue , :action => " knows" ))) == 3
253
253
@test rem_edge! (mg, 1 , 2 )
254
254
@test length (props (mg, 1 , 2 )) == 0
255
- @test length (set_props! (mg, Dict (:name => " testgraph" , :type => " undirected" ))) == 2
255
+ @test length (set_props! (mg, Dict (:name => " testgraph" , :type => " undirected" ))) == 2
256
256
257
257
mg = MetaGraph (CompleteGraph (3 ), 3.0 )
258
258
set_prop! (mg, 1 , :color , " blue" )
@@ -327,6 +327,19 @@ importall MetaGraphs
327
327
@test length (mga. eprops) == 1 # should only be edge 3=>2
328
328
@test props (mga, 3 , 2 )[:name ] == " 3, 4"
329
329
330
+ # test for #33
331
+ mga = MetaGraph (PathGraph (4 ))
332
+ set_prop! (mga, 1 , 2 , :name , " 1, 2" )
333
+ set_prop! (mga, 2 , 3 , :name , " 2, 3" )
334
+ set_prop! (mga, 3 , 4 , :name , " 3, 4" )
335
+ set_prop! (mga, 3 , :v , 3 )
336
+ set_prop! (mga, 4 , :v , 4 )
337
+ @test rem_vertex! (mga, nv (mga))
338
+ @test has_prop (mga, 2 , 3 , :name )
339
+ @test ! has_prop (mga, 3 , 4 , :name )
340
+ @test ! has_prop (mga, 4 , :v )
341
+ @test has_prop (mga, 3 , :v )
342
+
330
343
331
344
332
345
342
355
end
343
356
344
357
for i in 1 : 100
345
- set_prop! (G, i, :not_unique , " $(i% 5 ) " )
346
- set_prop! (dG, i, :not_unique , " $(i% 5 ) " )
358
+ set_prop! (G, i, :not_unique , " $(i % 5 ) " )
359
+ set_prop! (dG, i, :not_unique , " $(i % 5 ) " )
347
360
end
348
361
349
362
@test set_indexing_prop! (G, :name ) == Set {Symbol} ([:name ])
358
371
@test_throws ErrorException set_indexing_prop! (dG, 4 , :name , " dgnode_3" )
359
372
@test_throws ErrorException set_prop! (G, 3 , :name , " name3" )
360
373
@test_throws ErrorException set_prop! (dG, 3 , :name , " name3" )
361
- @test_throws ErrorException set_props! (G, 5 , Dict (:name => " name" , :other_name => " something" ))
362
- @test_throws ErrorException set_props! (dG, 5 , Dict (:name => " name" , :other_name => " something" ))
374
+ @test_throws ErrorException set_props! (G, 5 , Dict (:name => " name" , :other_name => " something" ))
375
+ @test_throws ErrorException set_props! (dG, 5 , Dict (:name => " name" , :other_name => " something" ))
363
376
377
+ info (" Ignore \" 'foo1' is already in index\" warnings" )
364
378
set_indexing_prop! (G, 50 , :name , " another name" )
365
379
set_indexing_prop! (G, 50 , :name , " another name" )
366
380
376
390
@test G[12 , :foo ] == " foo12"
377
391
@test G[" bar" , :foo ] == 42
378
392
@test G[42 , :foo ] == " bar"
379
- @test isa (G[:foo ], Dict{Any, Integer})
380
- @test isa (dG[:foo ], Dict{Any, Integer})
393
+ @test isa (G[:foo ], Dict{Any,Integer})
394
+ @test isa (dG[:foo ], Dict{Any,Integer})
381
395
382
396
383
397
@test dG[" foo30" , :foo ] == 30
0 commit comments