def test_has_year_no(self): """ Verify has_year() method returns False when the conditions are right. """ record = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", None, 18231) self.assert_(not record.has_year())
def test_has_year_no(self): """ Verify has_year() method returns False when the conditions are right. """ record = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", None, 18231) self.assertTrue(not record.has_year())
def test_has_year_yes(self): """ Verify has_year() method returns True when the conditions are right. """ record = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) self.assert_(record.has_year())
def test_equal(self): """Verify two 'equal' records are compared correctly.""" record1 = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) record2 = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) self.assertTrue(record1 == record2)
def test_unequal(self): """Verify two 'unequal' records are compared correctly.""" record1 = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) record2 = Record("Leonhard Euler", "Universitaet Basel", 1726, 38586) self.assertTrue(record1 < record2) self.assertTrue(record1 != record2) self.assertTrue(record2 > record1)
def test_add_node_object(self): """Test the add_node_object() method.""" record = Record("Leonhard Euler", "Universitaet Basel", 1726, 38586) node = Node(record, set(), set()) self.graph1.add_node_object(node) self.assertEqual(set([38586, 18231]), self.graph1.get_node_list()) self.assertEqual(self.graph1.seeds, set([18231]))
def test_equal(self): """Test comparison method for Nodes with identical records.""" record2 = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) node1 = Node(self.record, set(), set()) node2 = Node(record2, set(), set()) self.assertTrue(node1 == node2)
def test_str_no_inst_no_id(self): """Test __stre__() method for Node containing record without institution or year.""" record = Record(self.record.name, None, None, 18231) node = Node(record, set(), set()) nodestr = str(node) nodestrexpt = "Carl Friedrich Gau\xdf" self.assertEqual(nodestr, nodestrexpt)
def test_init(self): """Test the constructor.""" record = 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 test_unequal(self): """Test comparison method for Nodes with different records.""" record2 = Record("Leonhard Euler", "Universitaet Basel", 1726, 38586) node1 = Node(self.record, set(), set()) node2 = Node(record2, set(), set()) self.assertTrue(node1 < node2) self.assertTrue(node1 != node2) self.assertTrue(node2 > node1)
def test_str_no_year(self): """ Test __str__() method for Node containing record without year. """ record = Record(self.record.name, self.record.institution, None, 18231) node = Node(record, set(), set()) nodestr = str(node) nodestrexpt = "Carl Friedrich Gau\xdf \\nUniversit\xe4t Helmstedt" self.assertEqual(nodestr, nodestrexpt)
def test_has_institution_yes(self): """Verify has_institution() method returns True when the conditions are right.""" record = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) self.assert_(record.has_institution()) record = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) self.assertTrue(record.has_institution())
def test_unicode_no_inst(self): """Test __unicode__() method for record without institution.""" record = Record(self.record.name, None, 1799, 18231) recstr = record.__unicode__() recstrexpt = u"Carl Friedrich Gau\xdf \\n(1799)" self.assertEqual(recstr, recstrexpt)
def test_unicode_no_year(self): """Test __unicode__() method for record without year.""" record = Record(self.record.name, self.record.institution, None, 18231) recstr = record.__unicode__() recstrexpt = u"Carl Friedrich Gau\xdf \\nUniversit\xe4t Helmstedt" self.assertEqual(recstr, recstrexpt)
def setUp(self): self.record1 = Record("Carl Friedrich Gau\xdf", u"Universit\xe4t Helmstedt", 1799, 18231) self.node1 = Node(self.record1, set(), set()) self.graph1 = Graph(set([self.node1]))
def setUp(self): self.record = Record(u"Carl Friedrich Gau\xdf", u"Universit\xe4t Helmstedt", 1799, 18231)
def test_no_year(self): """Test __str__() method for record without year.""" record = Record(self.record.name, self.record.institution, None, 18231) recstr = str(record) recstrexpt = "Carl Friedrich Gau\xdf \\nUniversit\xe4t Helmstedt" self.assertEqual(recstr, recstrexpt)
def test_has_institution_no(self): """Verify has_institution() method returns False when the conditions are right.""" record = Record("Carl Friedrich Gauss", None, 1799, 18231) self.assert_(not record.has_institution())
class TestRecordMethods(unittest.TestCase): """Unit tests for the Record class.""" def setUp(self): self.record = Record(u"Carl Friedrich Gau\xdf", u"Universit\xe4t Helmstedt", 1799, 18231) def test_init(self): """Test the constructor.""" record = 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 test_init_bad_name(self): """Test constructor with bad 'name' parameter.""" self.assertRaises(TypeError, Record, 1, "Universitaet Helmstedt", 1799, 18231) def test_init_bad_institution(self): """Test constructor with bad 'institution' parameter.""" self.assertRaises(TypeError, Record, "Carl Friedrich Gauss", 1, 1799, 18231) def test_init_bad_year(self): """Test constructor with bad 'year' parameter.""" self.assertRaises(TypeError, Record, "Carl Friedrich Gauss", "Universitaet Helmstedt", "1799", 18231) def test_init_bad_id(self): """Test constructor with bad 'id' parameter.""" self.assertRaises(TypeError, Record, "Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, "18231") def test_cmp_equal(self): """Verify two 'equal' records are compared correctly.""" record1 = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) record2 = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) self.assert_(record1 == record2) def test_cmp_unequal(self): """Verify two 'unequal' records are compared correctly.""" record1 = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) record2 = Record("Leonhard Euler", "Universitaet Basel", 1726, 38586) self.assert_(record1 < record2) def test_has_institution_yes(self): """Verify has_institution() method returns True when the conditions are right.""" record = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) self.assert_(record.has_institution()) def test_has_institution_no(self): """Verify has_institution() method returns False when the conditions are right.""" record = Record("Carl Friedrich Gauss", None, 1799, 18231) self.assert_(not record.has_institution()) def test_has_year_yes(self): """ Verify has_year() method returns True when the conditions are right. """ record = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", 1799, 18231) self.assert_(record.has_year()) def test_has_year_no(self): """ Verify has_year() method returns False when the conditions are right. """ record = Record("Carl Friedrich Gauss", "Universitaet Helmstedt", None, 18231) self.assert_(not record.has_year()) def test_unicode_full(self): """Test __unicode__() method for complete record.""" recstr = self.record.__unicode__() recstrexpt = u"Carl Friedrich Gau\xdf \\nUniversit\xe4t Helmstedt \ (1799)" self.assertEqual(recstr, recstrexpt) def test_unicode_no_year(self): """Test __unicode__() method for record without year.""" record = Record(self.record.name, self.record.institution, None, 18231) recstr = record.__unicode__() recstrexpt = u"Carl Friedrich Gau\xdf \\nUniversit\xe4t Helmstedt" self.assertEqual(recstr, recstrexpt) def test_unicode_no_inst(self): """Test __unicode__() method for record without institution.""" record = Record(self.record.name, None, 1799, 18231) recstr = record.__unicode__() recstrexpt = u"Carl Friedrich Gau\xdf \\n(1799)" self.assertEqual(recstr, recstrexpt) def test_unicode_no_inst_no_id(self): """Test __unicode__() method for record without institution or year.""" record = Record(self.record.name, None, None, 18231) recstr = record.__unicode__() recstrexpt = u"Carl Friedrich Gau\xdf" self.assertEqual(recstr, recstrexpt)
def test_no_inst(self): """Test __str__() method for record without institution.""" record = Record(self.record.name, None, 1799, 18231) recstr = str(record) recstrexpt = "Carl Friedrich Gau\xdf \\n(1799)" self.assertEqual(recstr, recstrexpt)
def test_has_institution_no(self): """Verify has_institution() method returns False when the conditions are right.""" record = Record("Carl Friedrich Gauss", None, 1799, 18231) self.assertTrue(not record.has_institution())
def setUp(self): self.record = Record("Carl Friedrich Gau\xdf", "Universit\xe4t Helmstedt", 1799, 18231)
def test_no_inst_no_id(self): """Test __unicode__() method for record without institution or year.""" record = Record(self.record.name, None, None, 18231) recstr = str(record) recstrexpt = "Carl Friedrich Gau\xdf" self.assertEqual(recstr, recstrexpt)