Skip to content

Commit e5e1327

Browse files
committed
Adapt all other tests...
1 parent 0696aae commit e5e1327

6 files changed

+24
-24
lines changed

test/test-ancestors.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@testset "ancestors" begin
22
mtg = read_mtg("files/simple_plant.mtg")
3-
width_all = [nothing, nothing, nothing, 1.0, 6.0, nothing, 7.0]
3+
width_all = [nothing, nothing, nothing, 0.02, 0.1, 0.02, 0.1] # from print(descendants(mtg, :Width, self = true))
44

55
# Using a leaf node from the mtg:
66
leaf_node = mtg.children[2].children[3].children[4].children[5]
@@ -17,5 +17,5 @@
1717
@test ancestors(leaf_node, :Width, symbol = ("Leaf", "Internode")) == width_all[[4]]
1818

1919
@test ancestors(leaf_node, :Width, symbol = ("Leaf", "Internode"), self = true) ==
20-
width_all[5:-1:4]
20+
width_all[end:-1:end-1]
2121
end

test/test-conversion.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ mtg = read_mtg("files/simple_plant.mtg", Dict);
33
@testset "DataFrame" begin
44
df_mtg = DataFrame(mtg, [:scales, :Length])
55
@test df_mtg[1, :scales] == [0, 1, 2, 3, 3]
6-
@test df_mtg[7, :Length] == 12.0
6+
@test df_mtg[7, :Length] == 0.2
77
end
88

99

1010
@testset "MetaGraph" begin
1111
meta_mtg = MetaGraph(mtg)
1212
@test meta_mtg[1][:scales] == [0, 1, 2, 3, 3]
13-
@test meta_mtg[7][:Length] == 12.0
13+
@test meta_mtg[7][:Length] == 0.2
1414
end

test/test-delete-prune.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ end
3939
delete_nodes!(mtg, symbol = "Leaf")
4040
@test length(mtg) === length_start - 2
4141

42-
# Delete with a function, here we delete all nodes that have a parent with Length < 5:
42+
# Delete with a function, here we delete all nodes that have a parent with Length < 0.2:
4343
mtg = read_mtg(file)
4444
delete_nodes!(
4545
mtg,
4646
filter_fun = function (node)
4747
if !isroot(node)
48-
node.parent[:Length] !== nothing ? node.parent[:Length] < 5 : false
48+
node.parent[:Length] !== nothing ? node.parent[:Length] < 0.2 : false
4949
else
5050
false
5151
end
5252
end
5353
)
54-
@test length(mtg) === length_start - 2
54+
@test length(mtg) === length_start - 3
5555
end
5656

5757
@testset "prune! a node" begin

test/test-descendants.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
@testset "descendants" begin
2-
mtg = read_mtg("files/simple_plant.mtg");
3-
width_all = [nothing,nothing,1.0,6.0,nothing,7.0]
4-
@test descendants(mtg, :Width; type = Union{Nothing,Float64}) == width_all
5-
@test descendants(mtg, :Width) == width_all
2+
mtg = read_mtg("files/simple_plant.mtg")
3+
width_all = [nothing, nothing, 0.02, 0.1, 0.02, 0.1]
4+
@test descendants(mtg, :Width; type = Union{Nothing,Float64}) == width_all
5+
@test descendants(mtg, :Width) == width_all
66

77
d = descendants(mtg, :Width, scale = 1)
88
@test typeof(d) == Vector{Any}
99
@test length(d) == 1
10-
@test d[1] == width_all[1]
10+
@test d[1] === width_all[1]
1111
d_typed = descendants(mtg, :Width, type = Union{Nothing,Float64})
12-
@test typeof(d_typed) == Vector{Union{Nothing,Float64}}
12+
@test typeof(d_typed) == Vector{Union{Nothing,Float64}}
1313
@test descendants(mtg, :Width, symbol = ("Leaf", "Internode")) == width_all[3:end]
1414

1515
mtg2 = mtg[1][1][1][2]
1616
@test descendants(mtg2, :Width, symbol = "Leaf")[1] == width_all[end]
1717

1818
@test descendants(mtg2, :Width, symbol = ("Leaf", "Internode"), self = true) ==
19-
width_all[end - 1:end]
19+
width_all[end-1:end]
2020

2121
# Using the mutating version:
2222
@test descendants!(mtg, :Width) == descendants(mtg, :Width)
2323
@test descendants!(mtg2, :Width, symbol = ("Leaf", "Internode"), self = true) ==
24-
width_all[end - 1:end]
24+
width_all[end-1:end]
2525

2626
clean_cache!(mtg)
2727
# Get the leaves values:
28-
@test descendants(mtg, :Width; filter_fun = isleaf) == width_all[[end - 2,end]]
28+
@test descendants(mtg, :Width; filter_fun = isleaf) == width_all[[end - 2, end]]
2929

3030

3131
# descendants!(mtg, :Width, symbol = ("Leaf", "Internode"), self = true)

test/test-insert_node.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
mtg_5 = get_root(mtg_5)
6060

6161
@test mtg_5.MTG == template
62-
@test mtg_5[:Total_Length] == 32.0
62+
@test mtg_5[:Total_Length] 0.6
6363
@test mtg_5[1][:Length] == 1
6464
end
6565

@@ -71,14 +71,14 @@ end
7171
insert_parents!(
7272
mtg,
7373
template,
74-
node -> Dict{Symbol,Any}(:Total_Length => sum(descendants(node, :Length, ignore_nothing = true)),),
74+
node -> Dict{Symbol,Any}(:Total_Length => round(sum(descendants(node, :Length, ignore_nothing = true)), digits = 1),),
7575
scale = 2
7676
)
7777

7878
@test length(mtg) == length_before + 1
7979
@test mtg[1][1].MTG == template
8080
@test mtg[1][1].name == "node_8"
81-
@test mtg[1][1].attributes == Dict{Symbol,Any}(:Total_Length => 32.0)
81+
@test mtg[1][1].attributes == Dict{Symbol,Any}(:Total_Length => 0.6)
8282
end
8383

8484

test/test-nodes.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
mtg = read_mtg("files/simple_plant.mtg")
22

33
@testset "names" begin
4-
@test get_attributes(mtg) == [:scales, :description, :symbols, :FileName, :YY, :ZZ, :XX, :Length, :Width, :XEuler]
4+
@test get_attributes(mtg) == [:scales, :description, :symbols, :Length, :Width, :XEuler]
55
@test names(mtg) == get_attributes(mtg)
66
@test names(DataFrame(mtg))[8:end] == string.(names(mtg))
77
end
88

99

1010
@testset "get attribute value" begin
11-
@test mtg[1][:YY] == 0.0
12-
@test mtg[1].attributes[:YY] == 0.0
11+
@test mtg[1][1][1][:Width] == 0.02
12+
@test mtg[1][1][1].attributes[:Width] == 0.02
1313
end
1414

1515
@testset "set attribute value" begin
16-
mtg[1][:YY] = 1.0
17-
@test mtg[1][:YY] == 1.0
16+
mtg[1][1][1][:Width] = 1.0
17+
@test mtg[1][1][1][:Width] == 1.0
1818
end

0 commit comments

Comments
 (0)