52 |
|
|
53 |
|
|
54 |
def testfindComponents(): |
def testfindComponents(): |
55 |
|
def getNodes(fen): |
56 |
|
return fen.constgraph.findN_XAA_Iter() # not realistic! |
57 |
|
|
58 |
fen = ff.test.fen.newFen() |
fen = ff.test.fen.newFen() |
59 |
p = ff.swamp.Nodes.N() |
p = ff.swamp.Nodes.N() |
60 |
q = ff.swamp.Nodes.N() |
q = ff.swamp.Nodes.N() |
68 |
fen.graph.add(a,q,b) |
fen.graph.add(a,q,b) |
69 |
fen.graph.add(c,q,d) |
fen.graph.add(c,q,d) |
70 |
|
|
71 |
## no XAA problem if all nodes are subjects |
# no XAA problem in getNodes if all nodes are subjects |
72 |
# fen.graph.add(b,q,c) |
fen.graph.add(b,q,c) |
73 |
# fen.graph.add(d,q,a) |
fen.graph.add(d,q,a) |
74 |
|
|
75 |
result = Traversals.findComponents(p, fen.constgraph) |
result = Traversals.findComponents(getNodes(fen), p, fen.constgraph) |
|
nodes = fen.constgraph.findN_XAA_Iter() |
|
|
print "XAA doesn't find objects:" |
|
|
while nodes.hasNext(): |
|
|
print nodes.next() |
|
|
print result |
|
76 |
for x in a, b, c, d: # all single nodes are components |
for x in a, b, c, d: # all single nodes are components |
77 |
assert result.contains(x) |
assert result.contains(x) |
78 |
|
|
79 |
fen.graph.add(a,p,b) |
fen.graph.add(a,p,b) |
80 |
|
|
81 |
result = Traversals.findComponents(p, fen.constgraph) |
result = Traversals.findComponents(getNodes(fen), p, fen.constgraph) |
82 |
assert result.contains(a) != result.contains(b) # Either is representative |
assert result.contains(a) != result.contains(b) # Either is representative |
83 |
|
|
84 |
fen.graph.add(a,p,c) |
fen.graph.add(a,p,c) |
85 |
|
|
86 |
result = Traversals.findComponents(p, fen.constgraph) |
result = Traversals.findComponents(getNodes(fen), p, fen.constgraph) |
87 |
assert result.contains(a) # a has higher degree than b or c |
assert result.contains(a) # a has higher degree than b or c |
88 |
assert not result.contains(b) |
assert not result.contains(b) |
89 |
assert not result.contains(c) |
assert not result.contains(c) |
91 |
fen.graph.add(c,p,b) |
fen.graph.add(c,p,b) |
92 |
fen.graph.add(d,p,b) |
fen.graph.add(d,p,b) |
93 |
|
|
94 |
result = Traversals.findComponents(p, fen.constgraph) |
result = Traversals.findComponents(getNodes(fen), p, fen.constgraph) |
95 |
assert result.contains(b) # b has highest degree |
assert result.contains(b) # b has highest degree |
96 |
for x in a, c, d: |
for x in a, c, d: |
97 |
assert not result.contains(x) |
assert not result.contains(x) |