Infinity Calculator implementation for Assignment 2 in Computer Organization.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

81 lines
1.6 KiB

#include "infint.h"
#include "infint_util.c"
#include "infint_four_func.c"
#ifdef UNIT_TESTS
#include <assert.h>
void test_utils() {
infint_t *ii1, *ii2;
ii1 = infint_new(1);
assert(ii1->data[0] == 0);
assert(ii1->size == ii1->capacity == 1);
assert(ii1->sign == 0);
ii2 = infint_clone(ii1);
assert(ii2->data[0] == 0);
assert(ii2->size == ii1->capacity == 1);
assert(ii2->sign == 0);
infint_grow_to(ii1, 8);
assert(ii1->data[0] == 0);
assert(ii1->size == 8 && ii1->capacity == 8);
assert(ii1->sign == 0);
ii2->data[0] = 25;
infint_comp(ii2);
assert(ii2->data[0] == 75);
infint_comp(ii2);
assert(ii2->data[0] == 25);
assert(infint_abs_less_than(ii2, 50));
ii2->data[0] = 75;
assert(!infint_abs_less_than(ii2, 50));
ii1->data[7] = 1;
assert(!infint_abs_less_than(ii1, 50));
assert(infint_abs_less_than2(ii2,ii1));
assert(!infint_abs_less_than2(ii1,ii2));
ii1->size = 1;
ii1->data[0] = 50;
assert(infint_abs_less_than2(ii1,ii2));
infint_free(ii1);
infint_free(ii2);
ii1 = infint_new(3);
ii1->size = 3;
ii1->data[0] = 99;
ii1->data[1] = 0;
ii1->data[2] = 1;
ii2 = infint_slice(ii1, 1, 2);
assert(ii2->size == 2 && ii2->capacity == 2);
assert(ii2->data[0] == 0);
assert(ii2->data[1] == 1);
char *ii1s = infint_to_string(ii1);
assert(strcmp(ii1s, "10099") == 0);
free(ii1s);
infint_free(ii1);
infint_free(ii2);
}
#include "infint_test_ff.c"
void test_four_function() {
test_add();
test_sub();
test_mult();
test_div();
test_add2();
test_sub2();
test_mult2();
}
void test_infint() {
test_utils();
test_four_function();
}
#endif