Exemple #1
0
 def test_int(self):
     ''' Integers. '''
     self.assertEqual(util.lcm(3, 4), 12)
     self.assertEqual(util.lcm(8, 4), 8)
     self.assertEqual(util.lcm(3, 9), 9)
     self.assertEqual(util.lcm(15, 12), 60)
     self.assertEqual(util.lcm(300, 410), 12300)
Exemple #2
0
    def test_float(self):
        ''' Float. '''
        with self.assertRaisesRegexp(TypeError, '.*integers.*'):
            _ = util.lcm(1., 2)

        with self.assertRaisesRegexp(TypeError, '.*integers.*'):
            _ = util.lcm(1, 2.2)

        with self.assertRaisesRegexp(TypeError, '.*integers.*'):
            _ = util.lcm(1, 2, 3, 4.2)
Exemple #3
0
    def test_non_positive(self):
        ''' Non-positive values. '''
        with self.assertRaisesRegexp(ValueError, '.*positive.*'):
            _ = util.lcm(-1, 2)

        with self.assertRaisesRegexp(ValueError, '.*positive.*'):
            _ = util.lcm(1, -2)

        with self.assertRaisesRegexp(ValueError, '.*positive.*'):
            _ = util.lcm(3, 6, 9, 12, -21)

        with self.assertRaisesRegexp(ValueError, '.*positive.*'):
            _ = util.lcm(3, 0)

        with self.assertRaisesRegexp(ValueError, '.*positive.*'):
            _ = util.lcm(0, 3)

        with self.assertRaisesRegexp(ValueError, '.*positive.*'):
            _ = util.lcm(0, 5, 10, 15, 20)

        with self.assertRaisesRegexp(ValueError, '.*positive.*'):
            _ = util.lcm(5, 10, 0, 15, 20)
Exemple #4
0
 def test_no_arg(self):
     ''' No argument. '''
     with self.assertRaises(ValueError):
         _ = util.lcm()
Exemple #5
0
 def test_single(self):
     ''' Single value. '''
     for v in range(1, 10):
         self.assertEqual(util.lcm(v), v)
Exemple #6
0
 def test_multi(self):
     ''' Multiple values. '''
     self.assertEqual(util.lcm(4, 8, 10), 40)
     self.assertEqual(util.lcm(*range(6, 21, 3)), 180)