Skip to content

Commit f0e9651

Browse files
committed
Rel 0.1.0
1 parent 2540978 commit f0e9651

15 files changed

Lines changed: 254 additions & 313 deletions

test/runtests.jl

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,9 @@ using Test
88

99
end
1010

11-
@testset "DAG conversionss" begin
11+
@testset "DAG conversions" begin
1212

1313
include("test_dagitty_conversion.jl")
14-
@test d1 == OrderedDict(
15-
:S2 => :W,
16-
:W => [:Y, :V],
17-
:S1 => :U,
18-
:U => [:X, :V]
19-
)
20-
@test d2 == OrderedDict(
21-
:S2 => :W,
22-
:W => [:Y, :V],
23-
:U => [:X, :V],
24-
:S1 => :U
25-
)
26-
@test d3 == OrderedDict(
27-
:S2 => :W,
28-
:W => [:V, :Y],
29-
:U => [:V, :X],
30-
:S1 => :U
31-
)
32-
@test g1 == "dag { S2 <- W; W <- { Y V }; S1 <- U; U <- { X V } }"
33-
@test g2 == "dag { S2 <- W; W <- { Y V }; U <- { X V }; S1 <- U }"
34-
@test g3 == "dag { S2 <- W; W <- { V Y }; U <- { V X }; S1 <- U }"
35-
@test g4 == "dag { u <- v; w <- v; u <- x; s1 <- u; w <- y; s2 <- w }"
36-
@test dag.d == OrderedDict(
37-
:S2 => :W,
38-
:W => [:Y, :V],
39-
:S1 => :U,
40-
:U => [:X, :V]
41-
)
42-
4314
include("test_ggm_conversion.jl")
4415
include("test_graphviz_conversions.jl")
4516

@@ -63,12 +34,10 @@ end
6334

6435
end
6536

66-
6737
@testset "Methods" begin
6838

6939
include("test_sr6_4_3b.jl")
7040
include("test_ag.jl")
71-
println("\n")
7241

7342
end
7443

@@ -78,46 +47,17 @@ end
7847
include("test_open_paths_02.jl")
7948
include("test_open_paths_03.jl")
8049
include("test_open_paths_04.jl")
81-
#=
82-
@test allpaths[1] == [:w, :s, :a, :d]
83-
@test length(allpaths) == 4
84-
@test backdoorpaths == Array{Symbol,1}[]
85-
@test length(backdoorpaths) == 0
86-
@test show_dag_path(dag, allpaths[1]) == ":w ⇒ :s ⇐ :a ⇐ :d"
87-
@test adjustmentsets == Array{Symbol,1}[]
88-
=#
89-
println("\n")
9050

9151
end
52+
9253
@testset "SR6.4.2" begin
9354

9455
include("test_sr6_4_2.jl")
95-
#=
96-
@test allpaths[1] == [:x, :u, :b, :c, :y]
97-
@test length(allpaths) == 2
98-
@test backdoorpaths[1] == [:x, :u, :b, :c, :y]
99-
@test length(backdoorpaths) == 2
100-
@test show_dag_path(dag, backdoorpaths[1]) == ":x ⇐ :u ⇐ :a ⇒ :c ⇒ :y"
101-
@test adjustmentsets == [[:a], [:c]]
102-
include("test_sr6_4_2a.jl")
103-
@test adjustmentsets == [[:a], [:c]]
104-
=#
105-
println("\n")
10656

10757
end
10858

10959
@testset "SR6.4.3" begin
11060

11161
include("test_sr6_4_3.jl")
112-
#=
113-
@test allpaths[1] == [:w, :s, :a, :d]
114-
@test length(allpaths) == 4
115-
@test backdoorpaths == Array{Symbol,1}[]
116-
@test length(backdoorpaths) == 0
117-
@test show_dag_path(dag, allpaths[1]) == ":w ⇒ :s ⇐ :a ⇐ :d"
118-
@test adjustmentsets == Array{Symbol,1}[]
119-
=#
120-
println("\n")
12162

12263
end
123-

test/test_ag.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,24 @@ dag = DAG("ag_example", a)
3131

3232
fn = joinpath(mktempdir(), "ag.dot")
3333
to_graphviz(dag, fn)
34-
Sys.isapple() && run(`open -a GraphViz.app $(fn)`)
34+
#Sys.isapple() && run(`open -a GraphViz.app $(fn)`)
3535

3636
m = [:n3, :n5, :n6, :n15, :n16];
3737
c = [:n4, :n7];
3838

39-
fr = test_ag(a; m=m, c=c)
39+
fr = test_ag(a; m=m, c=c, debug=false)
4040

4141
fr1 = ancestral_graph(a; m=m, c=c)
42-
@test all(fr .== fr1)
4342

44-
fr2 = test_ag(dag.a; m=m, c=c)
45-
for i in names(fr, 1)
46-
for j in names(fr, 1)
47-
@test fr[i, j] == fr2[i, j]
43+
@testset "Ancestral graph" begin
44+
45+
@test all(fr .== fr1)
46+
47+
fr2 = test_ag(dag.a; m=m, c=c)
48+
for i in names(fr, 1)
49+
for j in names(fr, 1)
50+
@test fr[i, j] == fr2[i, j]
51+
end
4852
end
49-
end
5053

51-
println()
52-
display(fr)
53-
println()
54+
end

test/test_d_separation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ProjDir = @__DIR__
55
cd(ProjDir) #do
66

77
fname = scm_path("..", "examples", "Shipley", "fig2.6", "fig2.6.dot")
8-
Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
8+
#Sys.isapple() && run(`open -a GraphViz.app $(fname)`)
99

1010
# Read `=>` as `~` in regression models, or `<-` in causal models.
1111
d = OrderedDict(

test/test_dagitty_conversion.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,36 @@ d4 =OrderedDict(
2222
g4 = to_dagitty(d4)
2323

2424
dag = DAG("dag_1", dag_1)
25+
26+
@testset "dagitty conversions" begin
27+
28+
@test d1 == OrderedDict(
29+
:S2 => :W,
30+
:W => [:Y, :V],
31+
:S1 => :U,
32+
:U => [:X, :V]
33+
)
34+
@test d2 == OrderedDict(
35+
:S2 => :W,
36+
:W => [:Y, :V],
37+
:U => [:X, :V],
38+
:S1 => :U
39+
)
40+
@test d3 == OrderedDict(
41+
:S2 => :W,
42+
:W => [:V, :Y],
43+
:U => [:V, :X],
44+
:S1 => :U
45+
)
46+
@test g1 == "dag { S2 <- W; W <- { Y V }; S1 <- U; U <- { X V } }"
47+
@test g2 == "dag { S2 <- W; W <- { Y V }; U <- { X V }; S1 <- U }"
48+
@test g3 == "dag { S2 <- W; W <- { V Y }; U <- { V X }; S1 <- U }"
49+
@test g4 == "dag { u <- v; w <- v; u <- x; s1 <- u; w <- y; s2 <- w }"
50+
@test dag.d == OrderedDict(
51+
:S2 => :W,
52+
:W => [:Y, :V],
53+
:S1 => :U,
54+
:U => [:X, :V]
55+
)
56+
57+
end

test/test_ggm_conversion.jl

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,50 @@
1-
using StructuralCausalModels
2-
SymbolList = Union{Nothing, Symbol, Vector{Symbol}}
1+
using StructuralCausalModels, Test
32

43
ggm_1 = " DAG(U ~X+V, S1~U, W~V+Y, S2~W, order=FALSE)";
54
ggm_2 = " DAG(U ~X+V, S1~U, W~V+Y, S2~W)";
65

7-
d1 = from_ggm(ggm_1)
8-
d1 |> display
9-
d2 = from_ggm(ggm_2)
10-
d2 |> display
11-
println()
12-
13-
g1 = to_ggm(d1)
14-
g1 |> display
15-
g2 = to_ggm(d2)
16-
g2 |> display
17-
18-
d3 =OrderedDict{SymbolList, SymbolList}(
19-
[:u, :w] => :v,
20-
[:u] => :x,
21-
:s1 => [:u],
22-
:w => :y,
23-
[:s2] => [:w]
24-
)
25-
26-
g3 = to_ggm(d3)
27-
g3 |> display
28-
29-
g4 = to_ggm(d3, order=true)
30-
g4 |> display
31-
32-
dag = DAG("ggm_1", ggm_1)
33-
dag |> display
6+
@testset "ggm conversions" begin
7+
8+
d1 = from_ggm(ggm_1)
9+
@test d1 == OrderedDict(
10+
:U => [:X, :V],
11+
:S1 => :U,
12+
:W => [:V, :Y],
13+
:S2 => :W
14+
)
15+
d2 = from_ggm(ggm_2)
16+
@test d2 == OrderedDict(
17+
:U => [:X, :V],
18+
:S1 => :U,
19+
:W => [:V, :Y],
20+
:S2 => :W
21+
)
22+
23+
g1 = to_ggm(d1)
24+
@test g1 == "DAG(U ~ X + V, S1 ~ U, W ~ V + Y, S2 ~ W)"
25+
g2 = to_ggm(d2)
26+
@test g2 == "DAG(U ~ X + V, S1 ~ U, W ~ V + Y, S2 ~ W)"
27+
28+
d3 =OrderedDict(
29+
[:u, :w] => :v,
30+
[:u] => :x,
31+
:s1 => [:u],
32+
:w => :y,
33+
[:s2] => [:w]
34+
);
35+
36+
g3 = to_ggm(d3)
37+
@test g3 == "DAG(u ~ v, w ~ v, u ~ x, s1 ~ u, w ~ y, s2 ~ w)"
38+
39+
g4 = to_ggm(d3, order=true)
40+
@test g4 == "DAG(u ~ v, w ~ v, u ~ x, s1 ~ u, w ~ y, s2 ~ w, order=TRUE)"
41+
42+
dag = DAG("ggm_1", ggm_1)
43+
@test dag.d == OrderedDict(
44+
:U => [:X, :V],
45+
:S1 => :U,
46+
:W => [:V, :Y],
47+
:S2 => :W
48+
)
49+
50+
end

test/test_graphviz_conversions.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ d = from_ggm("DAG(
2626
);
2727

2828
dag = DAG("marks", d, df=df);
29-
show(dag)
30-
3129
fn = joinpath(mktempdir(), "marks.dot")
3230
to_graphviz(dag, fn)
33-
Sys.isapple() && run(`open -a GraphViz.app $(fn)`)
31+
#Sys.isapple() && run(`open -a GraphViz.app $(fn)`)
32+
33+
@testset "GraphViz conversion" begin
34+
35+
@test read(fn, String) == "digraph marks {\n algebra -> vectors;\n algebra -> mechanics;\n algebra -> analysis;\n algebra -> statistics;\n vectors -> mechanics;\n analysis -> statistics;\n}\n"
3436

37+
end

0 commit comments

Comments
 (0)