[geneagrapher] 02/226: * Produced unit tests for Record class. This resolves ticket #3. * Wrote a couple new methods in Record. * Set svn:ignore property for a few files.
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Sat Jul 11 17:10:30 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 7a97c663d7a983ae5770def17f91c0a96a02f943
Author: David Alber <alber.david at gmail.com>
Date: Fri Apr 4 05:29:41 2008 +0000
* Produced unit tests for Record class. This resolves ticket #3.
* Wrote a couple new methods in Record.
* Set svn:ignore property for a few files.
---
src/GGraph.py | 40 ++++++++++++++++++++++++++++++++--
src/tests.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+), 2 deletions(-)
diff --git a/src/GGraph.py b/src/GGraph.py
index 20b5559..cbdfc06 100644
--- a/src/GGraph.py
+++ b/src/GGraph.py
@@ -1,14 +1,50 @@
class Record:
- "Record of a mathematician in the graph."
+ """
+ Container class storing record of a mathematician in the graph.
+ """
def __init__(self, name, institution, year, id):
+ """
+ Construct a Record object.
+
+ Parameters:
+ name: string containing mathematician's name
+ institution: string containing mathematician's instituion (empty if
+ none)
+ year: integer containing year degree was earned
+ id: integer containing Math Genealogy Project id value.
+ """
self.name = name
self.institution = institution
self.year = year
self.id = id
+
+ # Verify we got the types wanted.
+ if type(self.name) is not type('str'):
+ raise TypeError("Unexpected parameter type: expected string value for 'name'")
+ if type(self.institution) is not type('str'):
+ raise TypeError("Unexpected parameter type: expected string value for 'institution'")
+ if type(self.year) is not type(1):
+ raise TypeError("Unexpected parameter type: expected integer value for 'year'")
+ if type(self.id) is not type(1):
+ raise TypeError("Unexpected parameter type: expected integer value for 'id'")
def __cmp__(self, r2):
+ """
+ Compare a pair of mathematician records based on ids.
+ """
return self.id.__cmp__(r2.id)
-
+
+ def hasInstitution(self):
+ """
+ Return True if this record has an institution associated with it, else False.
+ """
+ return self.institution != ""
+
+ def hasYear(self):
+ """
+ Return True if this record has a year associated with it, else False.
+ """
+ return self.year != -1
class Node:
diff --git a/src/tests.py b/src/tests.py
new file mode 100644
index 0000000..7e54180
--- /dev/null
+++ b/src/tests.py
@@ -0,0 +1,70 @@
+import unittest
+import GGraph
+
+# Unit tests for GGraph.
+class TestRecordMethods(unittest.TestCase):
+ """
+ Unit tests for the GGraph.Record class.
+ """
+
+ def test001_init(self):
+ # Test constructor.
+ record = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231)
+ self.assertEqual(record.name, "Carl Friedrich Gauss")
+ self.assertEqual(record.institution, "Universitaet Helmstedt")
+ self.assertEqual(record.year, 1799)
+ self.assertEqual(record.id, 18231)
+
+ def test002_init_bad_name(self):
+ # Test constructor with bad 'name' parameter.
+ self.assertRaises(TypeError, GGraph.Record, 1, "Universitaet Helmstedt", 1799, 18231)
+
+ def test003_init_bad_institution(self):
+ # Test constructor with bad 'institution' parameter.
+ self.assertRaises(TypeError, GGraph.Record, "Carl Friedrich Gauss", 1, 1799, 18231)
+
+ def test004_init_bad_year(self):
+ # Test constructor with bad 'year' parameter.
+ self.assertRaises(TypeError, GGraph.Record, "Carl Friedrich Gauss",
+ "Universitaet Helmstedt", "1799", 18231)
+
+ def test005_init_bad_id(self):
+ # Test constructor with bad 'id' parameter.
+ self.assertRaises(TypeError, GGraph.Record, "Carl Friedrich Gauss",
+ "Universitaet Helmstedt", 1799, "18231")
+
+ def test006_cmp_equal(self):
+ # Verify two 'equal' records are compared correctly.
+ record1 = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231)
+ record2 = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231)
+ self.assert_(record1 == record2)
+
+ def test007_cmp_unequal(self):
+ # Verify two 'unequal' records are compared correctly.
+ record1 = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231)
+ record2 = GGraph.Record("Leonhard Euler", "Universitaet Basel", 1726, 38586)
+ self.assert_(record1 < record2)
+
+ def test008_hasInstitution_yes(self):
+ # Verify hasInstitution() method returns True when the conditions are right.
+ record = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231)
+ self.assert_(record.hasInstitution())
+
+ def test009_hasInstitution_yes(self):
+ # Verify hasInstitution() method returns False when the conditions are right.
+ record = GGraph.Record("Carl Friedrich Gauss", "", 1799, 18231)
+ self.assert_(not record.hasInstitution())
+
+ def test010_hasYear_yes(self):
+ # Verify hasYear() method returns True when the conditions are right.
+ record = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231)
+ self.assert_(record.hasYear())
+
+ def test011_hasYear_no(self):
+ # Verify hasYear() method returns False when the conditions are right.
+ record = GGraph.Record("Carl Friedrich Gauss", "Universitaet Helmstedt", -1, 18231)
+ self.assert_(not record.hasYear())
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file
--
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