Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import math
- import unittest
- try: import a2 as sol
- except: print >> sys.stderr, "Missing ass02"
- try: import aggregate
- except: print >> sys.stderr, "Missing aggregate"
- try: import cube
- except: print >> sys.stderr, "Missing cube"
- try: import tax
- except: print >> sys.stderr, "Missing tax"
- try: import snakeoil
- except: print >> sys.stderr, "Missing snakeoil"
- try: import nyctime
- except: print >> sys.stderr, "Missing nyctime"
- try: import digit
- except: print >> sys.stderr, "Missing digit"
- all_perms = [
- (3, 11, -2),
- (3, -2, 11),
- (11, 3, -2),
- (11, -2, 3),
- (-2, 3, 11),
- (-2, 11, 3),
- (100, 2, 121),
- (1, 10.0, 21.0),
- (7.0, 2.5, 3.1)
- ]
- class assignment02(unittest.TestCase):
- def test_min(self):
- """ Testing my_min (Q1a) """
- for p, q, r in all_perms:
- self.assertEqual(aggregate.my_min(p,q,r), sol.my_min(p,q,r))
- def test_mean(self):
- """ Testing my_mean (Q1b) """
- for p, q, r in all_perms:
- self.assertAlmostEqual(aggregate.my_mean(p,q,r), sol.my_mean(p,q,r))
- def test_med(self):
- """ Testing my_mean (Q1c) """
- for p, q, r in all_perms:
- self.assertEqual(aggregate.my_med(p,q,r), sol.my_med(p,q,r))
- def test_perfectcube(self):
- """ Testing isPerfectCube (Q2) """
- tests = range(1, 45**3 + 1)
- for test in tests:
- self.assertEqual(cube.isPerfectCube(test), sol.isPerfectCube(test), test)
- def test_tax(self):
- """ Testing Tax brackets (Q3) """
- K = 1000
- deductions = [20000, 500 , 12345]
- borders = [50000, 150*K, 300*K, 500*K, 750*K, 1000*K, 2000*K, 4000*K]
- genpm = [ v + a for a in [-7, -2, 0, 2, 9] for v in borders ] + [ b + 100*K for b in borders ]
- for test in genpm:
- for deduct in deductions:
- self.assertAlmostEqual(tax.calculateTax(test, deduct), sol.calculateTax(test, deduct),2)
- def test_snakeoil(self):
- tests = [4.8, 5, 7, 9, 11, 15.0, 71, 99, 99.95, 100 , 100.425, 101, 230, 1024.1]
- for test in tests:
- self.assertAlmostEqual(snakeoil.price(test), sol.price(test), 2, "Case: {0}".format(test))
- def test_nyctime(self):
- tests = range(24)
- for hr in tests:
- self.assertEqual(nyctime.nycHour(hr), sol.nycHour(hr), "Testing {0}".format(hr))
- def test_kthDigit(self):
- tests = [ 498698787, 356, 29851, 2768175, 828581, 1, 17682 ]
- for num in tests:
- for b in range(2, 78):
- for k in range(0, int(math.log10(num))+1):
- self.assertEqual(digit.kthDigit(num, b, k), sol.kthDigit(num, b, k))
- if __name__ == '__main__':
- unittest.main(verbosity=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement