def main():
    """
        This function is used to execute the module as a standalone
        module.
    """
    parser = argparse.ArgumentParser()
    group1 = parser.add_argument_group()
    group2 = parser.add_mutually_exclusive_group(required=True)

    group1.add_argument('x',
                        help='The first value in the equation',
                        type=check_type)
    group1.add_argument('y',
                        help='The second value in the equation',
                        type=check_type)
    group2.add_argument('--add', action='store_true')
    group2.add_argument('--subtract', action='store_true')
    group2.add_argument('--multiply', action='store_true')
    group2.add_argument('--divide', action='store_true')
    group2.add_argument('--modulus', action='store_true')

    args = parser.parse_args()

    if args.add:
        print(add(args.x, args.y))
    if args.subtract:
        print(subtract(args.x, args.y))
    if args.multiply:
        print(multiply(args.x, args.y))
    if args.divide:
        print(divide(args.x, args.y))
    if args.modulus:
        print(modulus(args.x, args.y))
예제 #2
0
 def test_modulus_float_remainder(self):
     """Validates that add yields the expected results"""
     self.assertEqual(calculator.modulus(5.0, 2.0), 1.0)
예제 #3
0
 def test_modulus_float(self):
     """Validates that add yields the expected results"""
     self.assertEqual(calculator.modulus(8.0, 2.0), 0.0)
예제 #4
0
 def test_modulus_float_by_zero(self):
     """Validates that an exception raises when dividing by 0"""
     with self.assertRaises(ZeroDivisionError):
         calculator.modulus(4, 0.0)
예제 #5
0
 def test_modulus_integer_remainder(self):
     """Validates that add yields the expected results"""
     self.assertEqual(calculator.modulus(5, 2), 1)
예제 #6
0
 def test_modulus_non_int_non_float_exception(self):
     """Validates that an exception raises when adding strings"""
     data_sets = [[], '', {}]
     for data_set in data_sets:
         with self.assertRaises(TypeError):
             calculator.modulus(data_set, data_set)