bool test_big_int_copy_function_call (Test *test) { BigInt *a, *b, *to; TITLE (); CATCH (!(a = big_int_create (123451234512345))); CATCH (!(b = big_int_create (123451234512345))); CATCH (!(to = big_int_create (0))); CATCH (!big_int_mul (a, b, to)); CATCH (!big_int_mul (a, to, b)); memory_commit_limit (memory_commit_size ()); CATCH (big_int_copy (b, a)); CATCH (error_at (0).error != ErrorFunctionCall); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
bool test_big_int_mul_invalid_argument_3 (Test *test) { BigInt a, b; TITLE (); CATCH (big_int_mul (&a, &b, NULL)); CATCH (error_at (0).error != ErrorInvalidArgument); CATCH (error_at (0).code != 3); PASS (); }
bool test_big_int_mul_invalid_argument_2 (Test *test) { BigInt a, to; TITLE (); CATCH (big_int_mul (&a, NULL, &to)); CATCH (error_at (0).error != ErrorInvalidArgument); CATCH (error_at (0).code != 2); PASS (); }
bool test_big_int_mul_invalid_operation_2 (Test *test) { BigInt a, b, to; TITLE (); a.digits = 1; b.digits = 0; CATCH (big_int_mul (&a, &b, &to)); CATCH (error_at (0).error != ErrorInvalidOperation); CATCH (error_at (0).code != 2); PASS (); }
bool test_big_int_mul_2 (Test *test) { BigInt *a, *b, *to; TITLE (); CATCH (!(a = big_int_create (123451234512345))); CATCH (!(b = big_int_create (123451234512345))); CATCH (!(to = big_int_create (0))); CATCH (!big_int_mul (a, b, to)); CATCH (!big_int_equals_string (to, "15240207302622001229957399025")); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
bool test_big_int_mul_1 (Test *test) { BigInt *a, *b, *to; TITLE (); CATCH (!(a = big_int_create (12))); CATCH (!(b = big_int_create (34))); CATCH (!(to = big_int_create (0))); CATCH (!big_int_mul (a, b, to)); CATCH (!big_int_equals_string (to, "408")); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
bool test_big_int_mul_function_call_1 (Test *test) { BigInt *a, *b, *to; TITLE (); CATCH (!(a = big_int_create (2))); CATCH (!(b = big_int_create (3))); CATCH (!(to = big_int_create (0))); memory_commit_limit (memory_commit_size ()); CATCH (big_int_mul (a, b, to)); CATCH (error_at (0).error != ErrorFunctionCall); CATCH (error_at (0).code != 1); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
bool test_big_int_mul_function_call_3 (Test *test) { BigInt *a, *b, *to; TITLE (); CATCH (!(a = big_int_create (10000000000000000000ULL))); CATCH (!(b = big_int_create (10000000000000000000ULL))); CATCH (!(to = big_int_create (0))); memory_commit_limit (memory_commit_size () + sizeof (size_t) + sizeof (BigInt) + sizeof (size_t) + 32 + sizeof (size_t) + sizeof (BigInt) + sizeof (size_t) + 32 + sizeof (size_t) + sizeof (BigInt) + sizeof (size_t) + 32 - 1); CATCH (big_int_mul (a, b, to)); CATCH (error_at (0).error != ErrorFunctionCall); CATCH (error_at (0).code != 3); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
int term(big_int *a) { big_int *b = NULL; int result = 0; b = big_int_create(1); if (b == NULL) { printf("error when creating [b]\n"); result = 1; goto done; } if (term1(a)) { result = 2; goto done; } while (1) { switch ((int) curr_lex.token) { case '*' : match('*'); if (term1(b)) { result = 3; goto done; } if (is_mod) { if (big_int_mulmod(a, b, module, a)) { printf("error in big_int_mulmod()\n"); result = 4; goto done; } } else { if (big_int_mul(a, b, a)) { printf("error in big_int_mul()\n"); result = 5; goto done; } } continue; case '/' : case DIV1 : match(curr_lex.token); if (term1(b)) { result = 6; goto done; } if (is_zero(b)) { printf("division by zero\n"); result = 7; goto done; } if (is_mod) { switch (big_int_divmod(a, b, module, a)) { case 0: break; case 2: printf("GCD(b, modulus) != 1\n"); result = 8; goto done; default : printf("error in big_int_divmod()\n"); result = 8; goto done; } } else { if (big_int_div(a, b, a)) { printf("error in big_int_div()\n"); result = 9; goto done; } } continue; case '%' : case MOD1 : match(curr_lex.token); if (term1(b)) { result = 10; goto done; } if (is_zero(b)) { printf("division by zero\n"); result = 11; goto done; } if (big_int_mod(a, b, a)) { printf("error in big_int_mod()\n"); result = 12; goto done; } continue; default : goto done; } } done: big_int_destroy(b); return result; }