def test_int(self): ''' Integers. ''' self.assertEqual(util.gcd(3, 4), 1) self.assertEqual(util.gcd(8, 4), 4) self.assertEqual(util.gcd(3, 9), 3) self.assertEqual(util.gcd(15, 12), 3) self.assertEqual(util.gcd(300, 410), 10)
def test_float(self): ''' Float. ''' with self.assertRaisesRegexp(TypeError, '.*integers.*'): _ = util.gcd(1., 2) with self.assertRaisesRegexp(TypeError, '.*integers.*'): _ = util.gcd(1, 2.2) with self.assertRaisesRegexp(TypeError, '.*integers.*'): _ = util.gcd(1, 2, 3, 4.2)
def test_non_positive(self): ''' Non-positive values. ''' with self.assertRaisesRegexp(ValueError, '.*positive.*'): _ = util.gcd(-1, 2) with self.assertRaisesRegexp(ValueError, '.*positive.*'): _ = util.gcd(1, -2) with self.assertRaisesRegexp(ValueError, '.*positive.*'): _ = util.gcd(3, 6, 9, 12, -21) with self.assertRaisesRegexp(ValueError, '.*positive.*'): _ = util.gcd(3, 0) with self.assertRaisesRegexp(ValueError, '.*positive.*'): _ = util.gcd(0, 3) with self.assertRaisesRegexp(ValueError, '.*positive.*'): _ = util.gcd(0, 5, 10, 15, 20) with self.assertRaisesRegexp(ValueError, '.*positive.*'): _ = util.gcd(5, 10, 0, 15, 20)
def test_no_arg(self): ''' No argument. ''' with self.assertRaises(ValueError): _ = util.gcd()
def test_single(self): ''' Single value. ''' for v in range(1, 10): self.assertEqual(util.gcd(v), v)
def test_multi(self): ''' Multiple values. ''' self.assertEqual(util.gcd(4, 8, 10), 2) self.assertEqual(util.gcd(*range(6, 21, 3)), 3)