Example #1
0
    def post(self, request):

        # Assign the form with the request content
        form = LongIntForm(request.POST)
        # Verify the form
        if form.is_valid():
            form_dict = form.cleaned_data

            # Convert the numbers to int array
            number1 = str_to_int_array(form_dict["number1"])
            number2 = str_to_int_array(form_dict["number2"])

            # Perform long multiplication
            result = long_int_multiplication(number1, number2)

            # Convert the result to str
            result_str = int_array_to_str(result)

            return render(request, 'app/result.html', {'data': result_str})
        else:
            form = LongIntForm()
            return render(request, 'app/multiply.html', {'form': form})
Example #2
0
    def test_multiply_by_zero(self):

        number1 = [7,8]
        number2 = [ 0]

        self.assertEqual(long_int_multiplication(number1, number2), [0])
Example #3
0
    def test_multiply_numbers_with_remainder(self):

        number1 = [7,8]
        number2 = [ 2,3]

        self.assertEqual(long_int_multiplication(number1, number2), [1,7,9,4])
Example #4
0
    def test_multiply_numbers_with_different_length(self):

        number1 = [7,8]
        number2 = [ 2]

        self.assertEqual(long_int_multiplication(number1, number2), [1,5,6])
Example #5
0
    def test_multiply_numbers_with_same_length(self):

        number1 = [7,8]
        number2 = [ 1 ,1]

        self.assertEqual(long_int_multiplication(number1, number2), [8,5,8])