Skip to content

Commit f1175c1

Browse files
committed
Tweak docs
1 parent a6318d6 commit f1175c1

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

docs/make.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ TUTORIAL_DIR_JL = joinpath(dirname(@__DIR__), "test", "tutorial")
99
TUTORIAL_DIR_MD = joinpath(@__DIR__, "src", "tutorial")
1010

1111
for file in readdir(TUTORIAL_DIR_MD)
12-
rm(joinpath(TUTORIAL_DIR_MD, file))
12+
if endswith(file, ".md")
13+
rm(joinpath(TUTORIAL_DIR_MD, file))
14+
end
1315
end
1416

1517
for file in readdir(TUTORIAL_DIR_JL)
@@ -38,7 +40,7 @@ pages = [
3840
"Home" => "index.md",
3941
"Tutorial" => [
4042
markdown_title(joinpath(TUTORIAL_DIR_MD, file)) => joinpath("tutorial", file)
41-
for file in sort(readdir(TUTORIAL_DIR_MD))
43+
for file in sort(readdir(TUTORIAL_DIR_MD)) if endswith(file, ".md")
4244
],
4345
"API reference" => "api.md",
4446
]

test/tutorial/1_basics.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,22 @@ weighttype(weighted_default)
103103

104104
# You can use the `weight_function` keyword to specify a function which will transform edge metadata into a weight. This weight must always be the same type as the `default_weight`.
105105

106-
weighted = MetaGraph(Graph(); EdgeData=Float64, weight_function=identity);
107-
weighted[:red] = nothing;
108-
weighted[:blue] = nothing;
109-
weighted[:yellow] = nothing;
110-
weighted[:red, :blue] = 1.0;
111-
weighted[:blue, :yellow] = 2.0;
106+
weighted = MetaGraph(Graph(); EdgeData=Float64, weight_function=ed -> ed^2);
107+
108+
weighted[:alice] = nothing;
109+
weighted[:bob] = nothing;
110+
weighted[:alice, :bob] = 2.0;
112111
#-
113112
weight_matrix = Graphs.weights(weighted)
114113
#-
115114
size(weight_matrix)
116-
@test size(weight_matrix) == (3, 3) #src
115+
@test size(weight_matrix) == (2, 2) #src
117116
#-
118-
weight_matrix[1, 3]
119-
@test weight_matrix[1, 3] 1.0 #src
117+
weight_matrix[1, 2]
118+
@test weight_matrix[1, 2] 4.0 #src
120119
#-
121-
wf = get_weight_function(weighted) # identity
122-
wf(5.2)
123-
@test wf(5.2) 5.2 #src
120+
wf = get_weight_function(weighted)
121+
wf(3)
122+
@test wf(3) == 9 #src
124123

125124
# You can then use all functions from Graphs.jl that require weighted graphs (see the rest of the tutorial).

test/tutorial/2_graphs.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ using Test #src
1313
# We can make `MetaGraph`s based on (undirected) `Graph`s.
1414

1515
cities = MetaGraph(
16-
Graph(); VertexData=String, EdgeData=Int, weight_function=identity, default_weight=0
16+
Graph();
17+
Label=Symbol,
18+
VertexData=String,
19+
EdgeData=Int,
20+
weight_function=identity,
21+
default_weight=0,
1722
);
1823

1924
# Let us add some cities and the distance between them:
@@ -88,7 +93,7 @@ zero(cities)
8893
diameter(cities)
8994
@test diameter(cities) == 344 + 878 #src
9095
#-
91-
ds = dijkstra_shortest_paths(cities, 2);
96+
ds = dijkstra_shortest_paths(cities, 2)
9297
@test Tuple(ds.dists) == (344, 0, 344 + 878) #src
9398

9499
# Finally, let us remove some edges and vertices

0 commit comments

Comments
 (0)