mirror of
https://github.com/theoludwig/libcproject.git
synced 2025-05-21 23:21:15 +02:00
fix: more memory issues thanks to -fsanitize=address flag
Work In Progress #5
This commit is contained in:
@ -10,11 +10,25 @@ void convert_test() {
|
||||
}
|
||||
|
||||
void convert_character_to_string_test() {
|
||||
assert(assert_string_equal(convert_character_to_string('a'), "a"));
|
||||
assert(assert_string_equal(convert_character_to_string('A'), "A"));
|
||||
assert(assert_string_equal(convert_character_to_string('0'), "0"));
|
||||
assert(assert_string_equal(convert_character_to_string(' '), " "));
|
||||
assert(assert_string_equal(convert_character_to_string('\0'), ""));
|
||||
char* result = convert_character_to_string('a');
|
||||
assert(assert_string_equal(result, "a"));
|
||||
free(result);
|
||||
|
||||
result = convert_character_to_string('A');
|
||||
assert(assert_string_equal(result, "A"));
|
||||
free(result);
|
||||
|
||||
result = convert_character_to_string('0');
|
||||
assert(assert_string_equal(result, "0"));
|
||||
free(result);
|
||||
|
||||
result = convert_character_to_string(' ');
|
||||
assert(assert_string_equal(result, " "));
|
||||
free(result);
|
||||
|
||||
result = convert_character_to_string('\0');
|
||||
assert(assert_string_equal(result, ""));
|
||||
free(result);
|
||||
}
|
||||
|
||||
void convert_character_to_digit_test() {
|
||||
@ -63,33 +77,109 @@ void convert_string_to_number_test() {
|
||||
}
|
||||
|
||||
void convert_number_to_string_test() {
|
||||
assert(assert_string_equal(convert_number_to_string(0), "0"));
|
||||
assert(assert_string_equal(convert_number_to_string(1), "1"));
|
||||
assert(assert_string_equal(convert_number_to_string(2), "2"));
|
||||
assert(assert_string_equal(convert_number_to_string(3), "3"));
|
||||
assert(assert_string_equal(convert_number_to_string(4), "4"));
|
||||
assert(assert_string_equal(convert_number_to_string(5), "5"));
|
||||
assert(assert_string_equal(convert_number_to_string(6), "6"));
|
||||
assert(assert_string_equal(convert_number_to_string(7), "7"));
|
||||
assert(assert_string_equal(convert_number_to_string(8), "8"));
|
||||
assert(assert_string_equal(convert_number_to_string(9), "9"));
|
||||
assert(assert_string_equal(convert_number_to_string(10), "10"));
|
||||
assert(assert_string_equal(convert_number_to_string(11), "11"));
|
||||
assert(assert_string_equal(convert_number_to_string(20), "20"));
|
||||
assert(assert_string_equal(convert_number_to_string(-0), "0"));
|
||||
assert(assert_string_equal(convert_number_to_string(-1), "-1"));
|
||||
assert(assert_string_equal(convert_number_to_string(-20), "-20"));
|
||||
char* result = convert_number_to_string(0);
|
||||
assert(assert_string_equal(result, "0"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(1);
|
||||
assert(assert_string_equal(result, "1"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(2);
|
||||
assert(assert_string_equal(result, "2"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(3);
|
||||
assert(assert_string_equal(result, "3"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(4);
|
||||
assert(assert_string_equal(result, "4"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(5);
|
||||
assert(assert_string_equal(result, "5"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(6);
|
||||
assert(assert_string_equal(result, "6"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(7);
|
||||
assert(assert_string_equal(result, "7"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(8);
|
||||
assert(assert_string_equal(result, "8"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(9);
|
||||
assert(assert_string_equal(result, "9"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(10);
|
||||
assert(assert_string_equal(result, "10"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(11);
|
||||
assert(assert_string_equal(result, "11"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(20);
|
||||
assert(assert_string_equal(result, "20"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(-0);
|
||||
assert(assert_string_equal(result, "0"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(-1);
|
||||
assert(assert_string_equal(result, "-1"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_to_string(-20);
|
||||
assert(assert_string_equal(result, "-20"));
|
||||
free(result);
|
||||
}
|
||||
|
||||
void convert_number_from_base_to_another_test() {
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("15", 10, 16), "F"));
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("100000000", 2, 16), "100"));
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("FFFFFF", 16, 10), "16777215"));
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("1D57", 17, 35), "75C"));
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("80E", 20, 5), "100324"));
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("99", 10, 10), "99"));
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("3433024", 6, 28), "8008"));
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("30288G3A", 17, 36), "KF12OI"));
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("10", 9, 9), "10"));
|
||||
assert(assert_string_equal(convert_number_from_base_to_another("10E", 23, 8), "1037"));
|
||||
char* result = convert_number_from_base_to_another("15", 10, 16);
|
||||
assert(assert_string_equal(result, "F"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_from_base_to_another("100000000", 2, 16);
|
||||
assert(assert_string_equal(result, "100"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_from_base_to_another("FFFFFF", 16, 10);
|
||||
assert(assert_string_equal(result, "16777215"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_from_base_to_another("1D57", 17, 35);
|
||||
assert(assert_string_equal(result, "75C"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_from_base_to_another("80E", 20, 5);
|
||||
assert(assert_string_equal(result, "100324"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_from_base_to_another("99", 10, 10);
|
||||
assert(assert_string_equal(result, "99"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_from_base_to_another("3433024", 6, 28);
|
||||
assert(assert_string_equal(result, "8008"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_from_base_to_another("30288G3A", 17, 36);
|
||||
assert(assert_string_equal(result, "KF12OI"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_from_base_to_another("10", 9, 9);
|
||||
assert(assert_string_equal(result, "10"));
|
||||
free(result);
|
||||
|
||||
result = convert_number_from_base_to_another("10E", 23, 8);
|
||||
assert(assert_string_equal(result, "1037"));
|
||||
free(result);
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ void linked_list_reverse_test() {
|
||||
assert((list_reversed->head->next->next->data) == (void *)'B');
|
||||
assert((list_reversed->head->next->next->next->data) == (void *)'A');
|
||||
linked_list_free(list);
|
||||
linked_list_free(list_reversed);
|
||||
}
|
||||
|
||||
void linked_list_reverse_mutate_test() {
|
||||
|
Reference in New Issue
Block a user