Beispiel #1
0
 def post(self):
     num1 = request.form.get("num1")
     num2 = request.form.get("num2")
     try:
         result = mul_strings(num1, num2)
         return jsonify(dict(data=[num1, num2], result=result))
     except Exception as error:
         return jsonify({"error": str(error)})
 def test_mul_big_nums(self):
     num1 = "9934543747312321466784252345265479"
     num2 = "1241312898745643999"
     expected_result = [
         1, 2, 3, 3, 1, 8, 7, 7, 2, 9, 6, 6, 9, 1, 6, 7, 0, 3, 9, 9, 0, 2,
         7, 9, 7, 5, 8, 9, 9, 9, 3, 1, 3, 4, 3, 9, 0, 5, 7, 9, 7, 0, 2, 2,
         4, 7, 8, 2, 1, 0, 5, 2, 1
     ]
     self.assertEqual(mul_strings(num1, num2), expected_result)
 def test_mul_with_both_none(self):
     num1 = ""
     num2 = ""
     expected_result = []
     self.assertEqual(mul_strings(num1, num2), expected_result)
 def test_mul_with_none2(self):
     num1 = "321"
     num2 = ""
     expected_result = [3, 2, 1]
     self.assertEqual(mul_strings(num1, num2), expected_result)
 def test_mul_with_carry_out(self):
     num1 = "11"
     num2 = "11"
     expected_result = [1, 2, 1]
     self.assertEqual(mul_strings(num1, num2), expected_result)
 def test_mul_with_zero(self):
     num1 = "0"
     num2 = "3432432"
     expected_result = [0]
     self.assertEqual(mul_strings(num1, num2), expected_result)
 def test_mul_result(self):
     num1 = "22"
     num2 = "4"
     expected_result = [8, 8]
     self.assertEqual(mul_strings(num1, num2), expected_result)