[geneagrapher] 178/226: Add __contains__ method to Graph class.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Sat Jul 11 17:11:04 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository geneagrapher.

commit e1a2428c3656ba5a3f90633ac279a83a96742adc
Author: David Alber <alber.david at gmail.com>
Date:   Sat Nov 26 16:55:53 2011 -0800

    Add __contains__ method to Graph class.
---
 geneagrapher/graph/graph.py | 8 +++++++-
 tests/test_graph_methods.py | 8 ++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/geneagrapher/graph/graph.py b/geneagrapher/graph/graph.py
index f8ba7c8..b7466fd 100644
--- a/geneagrapher/graph/graph.py
+++ b/geneagrapher/graph/graph.py
@@ -40,11 +40,17 @@ of Node objects for 'seeds'")
         else:
             self.nodes = {}
 
+    def __contains__(self, id):
+        """
+        Return True if the given id is in the node list.
+        """
+        return id in self.nodes
+
     def has_node(self, id):
         """
         Check if the graph contains a node with the given id.
         """
-        return id in self.nodes
+        return id in self
 
     def get_node(self, id):
         """
diff --git a/tests/test_graph_methods.py b/tests/test_graph_methods.py
index 8852c26..b68e32c 100644
--- a/tests/test_graph_methods.py
+++ b/tests/test_graph_methods.py
@@ -35,6 +35,14 @@ class TestGraphMethods(unittest.TestCase):
         # Test the has_node() method for a False case.
         self.assertEquals(self.graph1.has_node(1), False)
 
+    def test004_has_node_true(self):
+        # Test the __contains__() method for a True case.
+        self.assertEquals(18231 in self.graph1, True)
+
+    def test005_has_node_false(self):
+        # Test the __contains__() method for a False case.
+        self.assertEquals(1 in self.graph1, False)
+
     def test006_get_node(self):
         # Test the get_node() method.
         node = self.graph1.get_node(18231)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/geneagrapher.git



More information about the debian-science-commits mailing list