-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsep_test.go
67 lines (62 loc) · 1.47 KB
/
dsep_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package dsep
import (
"fmt"
"reflect"
"testing"
)
func TestFindDSeperatioWithCommonCause(t *testing.T) {
var adjlist = make([][]int, 3)
adjlist[0] = []int{1, 2}
adjlist[1] = []int{}
adjlist[2] = []int{}
ans, err := FindDSeperation(adjlist, 1, []int{0})
if err != nil {
t.Error(err)
} else {
expect := []int{2}
if !reflect.DeepEqual(ans, expect) {
t.Error("Expected ", expect, " got ", ans)
}
}
}
func TestFindDSeperatioWithTrail(t *testing.T) {
var adjlist = make([][]int, 3)
adjlist[0] = []int{1}
adjlist[1] = []int{2}
adjlist[2] = []int{}
ans, err := FindDSeperation(adjlist, 0, []int{1})
if err != nil {
t.Error(err)
} else {
expect := []int{2}
if !reflect.DeepEqual(ans, expect) {
t.Error("Expected ", expect, " got ", ans)
}
}
}
func TestFindDSeperatioWithCommonEffect(t *testing.T) {
var adjlist = make([][]int, 3)
adjlist[0] = []int{}
adjlist[1] = []int{0}
adjlist[2] = []int{0}
ans, err := FindDSeperation(adjlist, 1, []int{})
if err != nil {
t.Error(err)
} else {
expect := []int{2}
if !reflect.DeepEqual(ans, expect) {
t.Error("Expected ", expect, " got ", ans)
}
}
}
// This example creates a Baysian network, where node-0 has two parents: node-1 and node-2,
// when node-0 is not observed, node-1 is D-separated from node-2.
func Example_findDSeperationWithCommonEffect() {
ans, err := FindDSeperation([][]int{[]int{}, []int{0}, []int{0}}, 1, []int{})
if err != nil {
panic(err)
}
fmt.Println(ans)
// Output:
// [2]
}