MCPcopy Index your code
hub / github.com/clips/pattern / test_adjacency

Method test_adjacency

test/test_graph.py:448–494  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

446 print "pattern.graph.edges()"
447
448 def test_adjacency(self):
449 # Assert adjacency map with different settings.
450 a = [
451 graph.adjacency(self.g),
452 graph.adjacency(self.g, directed=True),
453 graph.adjacency(self.g, directed=True, reversed=True),
454 graph.adjacency(self.g, stochastic=True),
455 graph.adjacency(self.g, heuristic=lambda id1, id2: 0.1),
456 ]
457 for i in range(len(a)):
458 a[i] = sorted((id1, sorted((id2, round(w,2)) for id2, w in p.items())) for id1, p in a[i].items())
459 self.assertEqual(a[0], [
460 ("a", [("b", 0.75), ("c", 1.0)]),
461 ("b", [("a", 0.75), ("d", 1.0)]),
462 ("c", [("a", 1.0)]),
463 ("d", [("b", 1.0), ("e", 1.0)]),
464 ("e", [("d", 1.0)]),
465 ("x", [])])
466 self.assertEqual(a[1], [
467 ("a", [("b", 0.75), ("c", 1.0)]),
468 ("b", [("d", 1.0)]),
469 ("c", []),
470 ("d", [("e", 1.0)]),
471 ("e", []),
472 ("x", [])])
473 self.assertEqual(a[2], [
474 ("a", []),
475 ("b", [("a", 0.75)]),
476 ("c", [("a", 1.0)]),
477 ("d", [("b", 1.0)]),
478 ("e", [("d", 1.0)]),
479 ("x", [])])
480 self.assertEqual(a[3], [
481 ("a", [("b", 0.43), ("c", 0.57)]),
482 ("b", [("a", 0.43), ("d", 0.57)]),
483 ("c", [("a", 1.0)]),
484 ("d", [("b", 0.5), ("e", 0.5)]),
485 ("e", [("d", 1.0)]),
486 ("x", [])])
487 self.assertEqual(a[4], [
488 ("a", [("b", 0.85), ("c", 1.1)]),
489 ("b", [("a", 0.85), ("d", 1.1)]),
490 ("c", [("a", 1.1)]),
491 ("d", [("b", 1.1), ("e", 1.1)]),
492 ("e", [("d", 1.1)]),
493 ("x", [])])
494 print "pattern.graph.adjacency()"
495
496 def test_dijkstra_shortest_path(self):
497 # Assert Dijkstra's algorithm (node1 -> node2).

Callers

nothing calls this directly

Calls 2

lenFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected