bool test_big_int_add_2 (Test *test) { BigInt *a, *b, *to; int i; TITLE (); CATCH (!(a = big_int_create (0))); CATCH (!(b = big_int_create (0))); CATCH (!(to = big_int_create (0))); a->memory[0] = 5U; b->memory[0] = 5U; for (i = 1; i < 32; i++) { a->memory[i] = 0U; b->memory[i] = 0U; } a->digits = 32; b->digits = 32; CATCH (!big_int_add (a, b, to)); CATCH (to->digits != 33); CATCH (to->memory[0] != 1U); for (i = 1; i < 33; i++) { CATCH (to->memory[i] != 0U); } big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
bool test_big_int_add_function_call_2 (Test *test) { BigInt *a, *b, *to; int i; TITLE (); CATCH (!(a = big_int_create (0))); CATCH (!(b = big_int_create (0))); CATCH (!(to = big_int_create (0))); CATCH (!(a->memory = memory_grow (a->memory, 33))); CATCH (!(b->memory = memory_grow (b->memory, 33))); a->memory[0] = 1U; b->memory[0] = 1U; for (i = 1; i < 33; i++) { a->memory[i] = 0U; b->memory[i] = 0U; } a->digits = 33; b->digits = 33; memory_commit_limit (memory_commit_size ()); CATCH (big_int_add (a, b, to)); CATCH (error_at (0).error != ErrorFunctionCall); CATCH (error_at (0).code != 2); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
bool test_big_int_add_invalid_argument_1 (Test *test) { TITLE (); CATCH (big_int_add (NULL, NULL, NULL)); CATCH (error_at (0).error != ErrorInvalidArgument); CATCH (error_at (0).code != 1); PASS (); }
bool test_big_int_add_invalid_argument_3 (Test *test) { BigInt a, b; TITLE (); CATCH (big_int_add (&a, &b, NULL)); CATCH (error_at (0).error != ErrorInvalidArgument); CATCH (error_at (0).code != 3); PASS (); }
bool test_big_int_add_invalid_operation_1 (Test *test) { BigInt a, b, to; TITLE (); a.digits = 0; CATCH (big_int_add (&a, &b, &to)); CATCH (error_at (0).error != ErrorInvalidOperation); CATCH (error_at (0).code != 1); PASS (); }
bool test_big_int_add_invalid_operation_4 (Test *test) { BigInt a, b; TITLE (); a.digits = 1; b.digits = 1; CATCH (big_int_add (&a, &b, &b)); CATCH (error_at (0).error != ErrorInvalidOperation); CATCH (error_at (0).code != 4); PASS (); }
bool test_big_int_add_1 (Test *test) { BigInt *a, *b, *to; TITLE (); CATCH (!(a = big_int_create (123))); CATCH (!(b = big_int_create (456))); CATCH (!(to = big_int_create (0))); CATCH (!big_int_add (a, b, to)); CATCH (to->digits != 3); CATCH (to->memory[0] != 5U); CATCH (to->memory[1] != 7U); CATCH (to->memory[2] != 9U); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
bool test_big_int_add_4 (Test *test) { BigInt *a, *b, *to; TITLE (); CATCH (!(a = big_int_create (999))); CATCH (!(b = big_int_create (11))); CATCH (!(to = big_int_create (0))); CATCH (!big_int_add (a, b, to)); CATCH (to->digits != 4); CATCH (to->memory[0] != 1U); CATCH (to->memory[1] != 0U); CATCH (to->memory[2] != 1U); CATCH (to->memory[3] != 0U); big_int_destroy (a); big_int_destroy (b); big_int_destroy (to); PASS (); }
bool test_big_int_to_value (Test *test) { BigInt *a, *b, *c; uint64_t value; TITLE (); CATCH (!(a = big_int_create (0))); CATCH (!big_int_to_value (a, &value)); CATCH (value != 0); big_int_destroy (a); CATCH (!(a = big_int_create (1))); CATCH (!big_int_to_value (a, &value)); CATCH (value != 1); big_int_destroy (a); CATCH (!(a = big_int_create (10))); CATCH (!big_int_to_value (a, &value)); CATCH (value != 10); big_int_destroy (a); CATCH (!(a = big_int_create (12))); CATCH (!big_int_to_value (a, &value)); CATCH (value != 12); big_int_destroy (a); CATCH (!(a = big_int_create (102))); CATCH (!big_int_to_value (a, &value)); CATCH (value != 102); big_int_destroy (a); CATCH (!(a = big_int_create ((uint64_t)-1))); CATCH (!big_int_to_value (a, &value)); CATCH (value != (uint64_t)-1); big_int_destroy (a); CATCH (!(a = big_int_create ((uint64_t)-1))); CATCH (!(b = big_int_create (1))); CATCH (!(c = big_int_create (0))); CATCH (!big_int_add (a, b, c)); CATCH (big_int_to_value (c, &value)); big_int_destroy (a); big_int_destroy (b); big_int_destroy (c); PASS (); }
int expr4(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 (term(a)) { result = 2; goto done; } while (1) { switch ((int) curr_lex.token) { case '+' : match('+'); if (term(b)) { result = 3; goto done; } if (is_mod) { if (big_int_addmod(a, b, module, a)) { printf("error in big_int_addmod()\n"); result = 4; goto done; } } else { if (big_int_add(a, b, a)) { printf("error in big_int_add()\n"); result = 5; goto done; } } continue; case '-' : match('-'); if (term(b)) { result = 6; goto done; } if (is_mod) { if (big_int_submod(a, b, module, a)) { printf("error in big_int_submod()\n"); result = 7; goto done; } } else { if (big_int_sub(a, b, a)) { printf("error in big_int_sub()\n"); result = 8; goto done; } } continue; default : goto done; } } done: big_int_destroy(b); return result; }