def test_noErdos(self): m = Author("Manuel") d = Author("Diego") m.addRelation(d) d.addRelation(m) self.assertEquals(erdos(d), INFINITY) self.assertEquals(erdos(m), INFINITY)
def test_relationsComplex(self): s = Author("Suya") e = Author("Erdos") s.addRelation(e) l = Author("Lucas") l.addRelation(s) self.assertEquals(erdos(l), 2)
def test_really_complex(self): m = Author("Manuel") d = Author("Diego") s = Author("Suya") l = Author("Lucas") a = Author("Augusto") f = Author("Fernando") e = Author("Erdos") m.addRelation(f) f.addRelation(l) l.addRelation(s) l.addRelation(e) l.addRelation(d) a.addRelation(e) f.addRelation(s) self.assertEquals(erdos(e), 0) self.assertEquals(erdos(l), 1) self.assertEquals(erdos(a), 1) self.assertEquals(erdos(f), 2) self.assertEquals(erdos(s), 2) self.assertEquals(erdos(d), 2) self.assertEquals(erdos(m), 3)
import sys def test(did_pass): """ Print the result of a test. """ linenum = sys._getframe(1).f_lineno # Get the caller's line number. if did_pass: msg = "Test at line {0} ok.".format(linenum) else: msg = ("Test at line {0} FAILED.".format(linenum)) print(msg) from erdos import * test( erdos("erdos_sample.txt") == [[("Smith, M.N.", 1), ("Hsueh, Z.", "infinity"), ("Chen, X.", 2)]])
def test_relations(self): s = Author("Suya") e = Author("Erdos") s.addRelation(e) self.assertEquals(erdos(s), 1) self.assertEquals(erdos(e), 0)