Esempio n. 1
0
 def test_connected(self):
     file_path = generate_path('files/tinyG.txt')
     with open(file_path, 'r') as f:
         g = Graph.from_file(f)
     cc = CC(g)
     assert cc.connected(0, 4)
     assert not cc.connected(0, 9)
Esempio n. 2
0
 def test_path_to(self):
     file_path = generate_path('files/tinyG.txt')
     with open(file_path, 'r') as f:
         g = Graph.from_file(f)
     p = BreadthFirstPaths(g, 0)
     paths = [i for i in p.pathTo(4)]
     assert paths == [0, 6, 4] or paths == [0, 5, 4]
Esempio n. 3
0
 def test_marked(self):
     file_path = generate_path('files/tinyG.txt')
     with open(file_path, 'r') as f:
         g = Graph.from_file(f)
     s = DepthFirstSearch(g, 0)
     assert s.marked(6)
     assert not s.marked(9)
Esempio n. 4
0
from src.ops.scalar import Num, Neg, Add, Mul
from src.graph.base import Graph

math = Add(Mul(Neg(Num(5.0)), Num(2.0)),
           Add(Mul(Num(-2.0), Neg(Num(2.0))), Num(3.0)))
g = Graph(math)
g.pprint()
g.eval()

math = Add(Neg(Num(2.0)), Num(-3.0))
g = Graph(math)
g.pprint()
g.reduce_neg()
g.pprint()
Esempio n. 5
0
 def test_v(self):
     file_path = generate_path('files/tinyG.txt')
     with open(file_path, 'r') as f:
         g = Graph.from_file(f)
     assert g.V() == 13
Esempio n. 6
0
 def test_count(self):
     file_path = generate_path('files/tinyG.txt')
     with open(file_path, 'r') as f:
         g = Graph.from_file(f)
     cc = CC(g)
     assert cc.count() == 3
Esempio n. 7
0
 def test_has_path_to(self):
     file_path = generate_path('files/tinyG.txt')
     with open(file_path, 'r') as f:
         g = Graph.from_file(f)
     p = BreadthFirstPaths(g, 0)
     assert p.hasPathTo(6)
Esempio n. 8
0
 def test_count(self):
     file_path = generate_path('files/tinyG.txt')
     with open(file_path, 'r') as f:
         g = Graph.from_file(f)
     s = DepthFirstSearch(g, 0)
     assert s.count() == 7
Esempio n. 9
0
 def test_adj(self):
     file_path = generate_path('files/tinyG.txt')
     with open(file_path, 'r') as f:
         g = Graph.from_file(f)
     adj = [i for i in g.adj(0)]
     assert adj == [6, 2, 1, 5]