def testMethod(): func = lib.getFunction('mylen', _fileName) for (l, r) in [([], 0), ([5], 1), (['a', 'b'], 2)]: res = func(l) if not assertlib.exact(res, r): return False, "mylen(%r) should be %i, but got %r" % \ (l, r, res) return True
def testMethod(): func = lib.getFunction('convertFromSeconds', _fileName) for (s, exp) in [(610, [0, 0, 10, 10]), (100000, [1, 3, 46, 40])]: res = func(s) if not assertlib.exact(res, exp): return False, "convertFromSeconds(%i) should be %r, but got %r" % \ (s, exp, res) return True
def testMethod(): func = lib.getFunction('flipside', _fileName) for (s, exp) in [('homework', 'workhome'), ('carpets', 'petscar')]: res = func(s) if not assertlib.exact(res, exp): return False, "flipside(%s) should be %s, but got %s" % ( s, exp, res) return True
def testMethod(): eps = 0.00001 func = lib.getFunction('scrabbleScore', _fileName) for (s, r) in [('quetzal', 25), ('jonquil', 23), ('syzygy', 25)]: res = func(s) if not assertlib.exact(res, r): return False, "scrabbleScore(%s) should be %i, but got %r" % \ (s, r, res) return True
def testMethod(): func = lib.getFunction('ind', _fileName) for (n, l, r) in [(42, [55, 77, 42, 12, 42, 100], 2), (42, range(100), 42), ('i', 'team', 4)]: res = func(n, l) if not assertlib.exact(res, r): return False, "ind(%i, %r) should be %i, but got %r" % \ (l, r, res) return True
def testMethod(): func = lib.getFunction('transcribe', _fileName) for (s, r) in [('ACGT TGCA', 'UGCAACGU'), ('GATTACA', 'CUAAUGU'), ('cs5', '')]: res = func(s) if not assertlib.exact(res, r): return False, "transcribe(%s) should be %s, but got %r" % \ (s, r, res) return True
def testMethod(): func = lib.getFunction('one_dna_to_rna', _fileName) for (s, r) in [('A', 'U'), ('C', 'G'), ('G', 'C'), ('T', 'A'), (' ', ''), ('.', ''), ('0', '')]: res = func(s) if not assertlib.exact(res, r): return False, "one_dna_to_rna(%s) should be %s, but got %r" % ( s, r, res) return True
def testMethod(): func = lib.getFunction('dbl', _fileName) for i in range(1, 10): res = func(i) exp = i * 2 if not assertlib.exact(res, exp): return False, "%i doubled should be %i, but got %i" % (i, exp, res) return True
def testMethod(): func = lib.getFunction('checkends', _fileName) for (s, exp) in [('no match', False), ('hah! a match', True), ('q', True)]: res = func(s) if not assertlib.exact(res, exp): return False, "checkends(%s) should be %r, but got %r" % ( s, exp, res) return True
def testMethod(): func = lib.getFunction('front3', _fileName) for s in ['Java', 'Chocolate', 'abc']: res = func(s) exp = s[:3] * 3 if not assertlib.exact(res, exp): return False, "front3(%s) should be %s, but got %s" % (s, exp, res) return True
def testMethod(): func = lib.getFunction('mult', _fileName) for i in range(10): for j in range(10): exp = i * j res = func(i, j) if not assertlib.exact(res, exp): return False, "mult(%i, %i) should be %i, but got %r" % \ (i, j, r, res) return True
def testMethod(): func = lib.getFunction('interp', _fileName) e = 0.00001 for (h, l, f, r) in [(1.0, 9.0, 0.25, 3.0), (1.0, 3.0, 0.25, 1.5), (2, 12, 0.22, 4.2)]: res = func(h, l, f) if not assertlib.between(res, r - e, r + e): return False, "interp(%f, %f, %f) should be %f, but got %f" % \ (h, l, f, r, res) return True
def testMethod(): eps = 0.00001 func = lib.getFunction('dot', _fileName) for (l, k, r) in [([5, 3], [6, 4], 42.0), ([1, 2, 3, 4], [10, 100, 1000, 10000], 43210.0), ([5, 3], [6], 0.0)]: res = func(l, k) if not assertlib.between(res, r - eps, r + eps): return False, "dot(%r, %r) should be %f, but got %r" % \ (l, k, r, res) return True
def testMethod(): eps = 0.00001 func = lib.getFunction('letterScore', _fileName) for (letters, r) in [('aeilnorstu', 1), ('dg', 2), ('bcmp', 3), ('fhvwy', 4), ('k', 5), ('jx', 8), ('qz', 10), (' ./=+!9', 0)]: for l in letters: res = func(l) if not assertlib.exact(res, r): return False, "letterScore(%s) should be %i, but got %r" % ( l, r, res) return True