mirror of
https://github.com/theoludwig/libcproject.git
synced 2024-12-11 21:13:00 +01:00
Compare commits
5 Commits
b3c17983b3
...
a7aef0b954
Author | SHA1 | Date | |
---|---|---|---|
|
a7aef0b954 | ||
336bbf6197 | |||
1be12c2a97 | |||
51d7123c8d | |||
6ac47429e8 |
@ -1,18 +1,35 @@
|
|||||||
#include "array_list.h"
|
#include "array_list.h"
|
||||||
|
|
||||||
struct array_list* array_list_initialization() {
|
struct array_list* array_list_initialization() {
|
||||||
|
return array_list_initialization_with_capacity(ARRAY_LIST_INITIAL_CAPACITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct array_list* array_list_initialization_with_capacity(size_t capacity) {
|
||||||
struct array_list* list = malloc(sizeof(struct array_list));
|
struct array_list* list = malloc(sizeof(struct array_list));
|
||||||
list->data = malloc(sizeof(void*) * ARRAY_LIST_INITIAL_CAPACITY);
|
if (list == NULL) {
|
||||||
|
perror("Error (array_list_initialization)");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
list->size = 0;
|
list->size = 0;
|
||||||
list->capacity = ARRAY_LIST_INITIAL_CAPACITY;
|
list->capacity = capacity;
|
||||||
|
list->capacity_step = capacity;
|
||||||
|
list->data = malloc(sizeof(void*) * list->capacity);
|
||||||
|
if (list->data == NULL) {
|
||||||
|
perror("Error (array_list_initialization)");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void array_list_add(struct array_list* list, void* element) {
|
void array_list_add(struct array_list* list, void* element) {
|
||||||
if (list->size >= list->capacity) {
|
if (list->size >= list->capacity) {
|
||||||
size_t previous_capacity = list->capacity;
|
size_t previous_capacity = list->capacity;
|
||||||
list->capacity += ARRAY_LIST_INITIAL_CAPACITY;
|
list->capacity += list->capacity_step;
|
||||||
list->data = realloc(list->data, sizeof(void*) * list->capacity);
|
list->data = realloc(list->data, sizeof(void*) * list->capacity);
|
||||||
|
if (list->data == NULL) {
|
||||||
|
perror("Error (array_list_add)");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
for (size_t index = previous_capacity; index < list->capacity; index++) {
|
for (size_t index = previous_capacity; index < list->capacity; index++) {
|
||||||
list->data[index] = NULL;
|
list->data[index] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@ -17,6 +18,7 @@ struct array_list {
|
|||||||
void** data;
|
void** data;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
|
size_t capacity_step;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +27,12 @@ struct array_list {
|
|||||||
*/
|
*/
|
||||||
struct array_list* array_list_initialization();
|
struct array_list* array_list_initialization();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initializes a new array list with a capacity.
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
struct array_list* array_list_initialization_with_capacity(size_t capacity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adds an element to the end of the array list.
|
* @brief Adds an element to the end of the array list.
|
||||||
*
|
*
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "test.h"
|
#include "assert.h"
|
||||||
|
|
||||||
bool assert_string_equal(const string_t actual, const string_t expected) {
|
bool assert_string_equal(const string_t actual, const string_t expected) {
|
||||||
if (strcmp(expected, actual) != 0) {
|
if (!string_equals(actual, expected)) {
|
||||||
printf("FAIL: expected = \"%s\" ; actual = \"%s\"\n", expected, actual);
|
printf("FAIL: expected = \"%s\" ; actual = \"%s\"\n", expected, actual);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -9,7 +9,7 @@ bool assert_string_equal(const string_t actual, const string_t expected) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool assert_string_not_equal(const string_t actual, const string_t expected) {
|
bool assert_string_not_equal(const string_t actual, const string_t expected) {
|
||||||
if (strcmp(expected, actual) == 0) {
|
if (string_equals(actual, expected)) {
|
||||||
printf("FAIL: expected = \"%s\" ; actual = \"%s\"\n", expected, actual);
|
printf("FAIL: expected = \"%s\" ; actual = \"%s\"\n", expected, actual);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
30
lib/assert.h
Normal file
30
lib/assert.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef __LIBCPROJECT_ASSERT__
|
||||||
|
#define __LIBCPROJECT_ASSERT__
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "string.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if the two strings are equal. If they are not equal, print the expected and actual strings.
|
||||||
|
*
|
||||||
|
* @param character
|
||||||
|
* @return bool
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
bool assert_string_equal(const string_t actual, const string_t expected);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if the two strings are not equal. If they are equal, print the expected and actual strings.
|
||||||
|
*
|
||||||
|
* @param character
|
||||||
|
* @return bool
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
bool assert_string_not_equal(const string_t actual, const string_t expected);
|
||||||
|
|
||||||
|
#endif
|
@ -32,9 +32,9 @@ bool character_get_is_digit(const char character) {
|
|||||||
return character >= '0' && character <= '9';
|
return character >= '0' && character <= '9';
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char character_get_alphabet_position(const char character) {
|
uint8_t character_get_alphabet_position(const char character) {
|
||||||
const char letter = character_to_lower(character);
|
const char letter = character_to_lower(character);
|
||||||
unsigned char position = 0;
|
uint8_t position = 0;
|
||||||
if (letter >= 'a' && letter <= 'z') {
|
if (letter >= 'a' && letter <= 'z') {
|
||||||
position = (letter - 'a') + 1;
|
position = (letter - 'a') + 1;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,7 @@ char character_to_lower(const char character);
|
|||||||
* @brief Check if the character is a digit ('0', '1', '2', '3', '4', '5', '6', '7, '8' or '9').
|
* @brief Check if the character is a digit ('0', '1', '2', '3', '4', '5', '6', '7, '8' or '9').
|
||||||
*
|
*
|
||||||
* @param character
|
* @param character
|
||||||
* @return true
|
* @return bool
|
||||||
* @return false
|
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
bool character_get_is_digit(const char character);
|
bool character_get_is_digit(const char character);
|
||||||
@ -59,9 +58,9 @@ bool character_get_is_digit(const char character);
|
|||||||
* Return 0 if the character is not a letter.
|
* Return 0 if the character is not a letter.
|
||||||
*
|
*
|
||||||
* @param character
|
* @param character
|
||||||
* @return unsigned char
|
* @return uint8_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
unsigned char character_get_alphabet_position(const char character);
|
uint8_t character_get_alphabet_position(const char character);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,9 +19,9 @@ char convert_digit_to_character(const char digit) {
|
|||||||
return digit + '0';
|
return digit + '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
long long convert_string_to_number(const string_t string) {
|
int64_t convert_string_to_number(const string_t string) {
|
||||||
bool is_negative = string[0] == '-';
|
bool is_negative = string[0] == '-';
|
||||||
long long integer = 0;
|
int64_t integer = 0;
|
||||||
size_t length = string_get_length(string);
|
size_t length = string_get_length(string);
|
||||||
for (size_t index = is_negative ? 1 : 0; index < length; index++) {
|
for (size_t index = is_negative ? 1 : 0; index < length; index++) {
|
||||||
integer = integer * 10 + convert_character_to_digit(string[index]);
|
integer = integer * 10 + convert_character_to_digit(string[index]);
|
||||||
@ -29,13 +29,13 @@ long long convert_string_to_number(const string_t string) {
|
|||||||
return is_negative ? integer * -1 : integer;
|
return is_negative ? integer * -1 : integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
string_t convert_number_to_string(const long long integer) {
|
string_t convert_number_to_string(const int64_t integer) {
|
||||||
if (integer == 0) {
|
if (integer == 0) {
|
||||||
return convert_character_to_string('0');
|
return convert_character_to_string('0');
|
||||||
}
|
}
|
||||||
bool is_negative = integer < 0;
|
bool is_negative = integer < 0;
|
||||||
size_t length = 1;
|
size_t length = 1;
|
||||||
long long current = mathematics_absolute_value(integer);
|
int64_t current = mathematics_absolute_value(integer);
|
||||||
while (current != 0) {
|
while (current != 0) {
|
||||||
current = current / 10;
|
current = current / 10;
|
||||||
length++;
|
length++;
|
||||||
@ -62,21 +62,21 @@ string_t convert_number_to_string(const long long integer) {
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned long base) {
|
string_t convert_number_from_base_10_to_base(uint64_t number, uint64_t base) {
|
||||||
if (number == 0) {
|
if (number == 0) {
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
int remainders[64];
|
int64_t remainders[64];
|
||||||
int index = 0;
|
int64_t index = 0;
|
||||||
while (number > 0) {
|
while (number > 0) {
|
||||||
remainders[index] = number % base;
|
remainders[index] = number % base;
|
||||||
number = number / base;
|
number = number / base;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
string_t result = malloc(sizeof(char) * (index + 1));
|
string_t result = malloc(sizeof(char) * (index + 1));
|
||||||
int index_result = 0;
|
int64_t index_result = 0;
|
||||||
for (int iteration = index - 1; iteration >= 0; iteration--) {
|
for (int64_t iteration = index - 1; iteration >= 0; iteration--) {
|
||||||
int remainder = remainders[iteration];
|
int64_t remainder = remainders[iteration];
|
||||||
if (remainder >= 10) {
|
if (remainder >= 10) {
|
||||||
result[index_result] = (char)((remainder - 10) + 'A');
|
result[index_result] = (char)((remainder - 10) + 'A');
|
||||||
} else {
|
} else {
|
||||||
@ -88,17 +88,17 @@ string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long convert_number_from_base_to_base_10(string_t number, unsigned long base) {
|
uint64_t convert_number_from_base_to_base_10(string_t number, uint64_t base) {
|
||||||
size_t length = string_get_length(number);
|
size_t length = string_get_length(number);
|
||||||
int exponent = length - 1;
|
int64_t exponent = length - 1;
|
||||||
unsigned long result = 0;
|
uint64_t result = 0;
|
||||||
int index = 0;
|
int64_t index = 0;
|
||||||
while (exponent >= 0) {
|
while (exponent >= 0) {
|
||||||
int current_number = (int)(number[index] - '0');
|
int64_t current_number = (int64_t)(number[index] - '0');
|
||||||
if (current_number >= 10) {
|
if (current_number >= 10) {
|
||||||
current_number = (int)(number[index] - 'A') + 10;
|
current_number = (int64_t)(number[index] - 'A') + 10;
|
||||||
} else {
|
} else {
|
||||||
current_number = (int)(number[index] - '0');
|
current_number = (int64_t)(number[index] - '0');
|
||||||
}
|
}
|
||||||
result = result + current_number * mathematics_pow(base, exponent);
|
result = result + current_number * mathematics_pow(base, exponent);
|
||||||
exponent--;
|
exponent--;
|
||||||
@ -107,6 +107,6 @@ unsigned long convert_number_from_base_to_base_10(string_t number, unsigned long
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
string_t convert_number_from_base_to_another(string_t number, unsigned long base_from, unsigned long base_target) {
|
string_t convert_number_from_base_to_another(string_t number, uint64_t base_from, uint64_t base_target) {
|
||||||
return convert_number_from_base_10_to_base(convert_number_from_base_to_base_10(number, base_from), base_target);
|
return convert_number_from_base_10_to_base(convert_number_from_base_to_base_10(number, base_from), base_target);
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,10 @@ char convert_digit_to_character(const char digit);
|
|||||||
* @brief Convert a string to a number.
|
* @brief Convert a string to a number.
|
||||||
*
|
*
|
||||||
* @param string
|
* @param string
|
||||||
* @return long long
|
* @return int64_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
long long convert_string_to_number(const string_t string);
|
int64_t convert_string_to_number(const string_t string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert a number to a string.
|
* @brief Convert a number to a string.
|
||||||
@ -54,7 +54,7 @@ long long convert_string_to_number(const string_t string);
|
|||||||
* @return string_t
|
* @return string_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
string_t convert_number_to_string(const long long integer);
|
string_t convert_number_to_string(const int64_t integer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert a number (base 10) to a string with a specific base.
|
* @brief Convert a number (base 10) to a string with a specific base.
|
||||||
@ -64,17 +64,17 @@ string_t convert_number_to_string(const long long integer);
|
|||||||
* @return string_t
|
* @return string_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned long base);
|
string_t convert_number_from_base_10_to_base(uint64_t number, uint64_t base);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert a number with a specific base to a number base 10.
|
* @brief Convert a number with a specific base to a number base 10.
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* @param base
|
* @param base
|
||||||
* @return int
|
* @return uint64_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
unsigned long convert_number_from_base_to_base_10(string_t number, unsigned long base);
|
uint64_t convert_number_from_base_to_base_10(string_t number, uint64_t base);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert a number with a specific base to a number of specific base.
|
* @brief Convert a number with a specific base to a number of specific base.
|
||||||
@ -85,6 +85,6 @@ unsigned long convert_number_from_base_to_base_10(string_t number, unsigned long
|
|||||||
* @return string_t
|
* @return string_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
string_t convert_number_from_base_to_another(string_t number, unsigned long base_from, unsigned long base_target);
|
string_t convert_number_from_base_to_another(string_t number, uint64_t base_from, uint64_t base_target);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
|
|
||||||
int filesystem_read(string_t path, byte_t **file_content, off_t *file_size) {
|
int filesystem_read(string_t path, byte_t **file_content, size_t *file_size) {
|
||||||
int file_descriptor = open(path, O_RDONLY);
|
int file_descriptor = open(path, O_RDONLY);
|
||||||
if (file_descriptor == -1) {
|
if (file_descriptor == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -15,7 +15,7 @@ int filesystem_read(string_t path, byte_t **file_content, off_t *file_size) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int filesystem_write(string_t path, byte_t *file_content, off_t file_size) {
|
int filesystem_write(string_t path, byte_t *file_content, size_t file_size) {
|
||||||
int file_descriptor = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
int file_descriptor = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||||
if (file_descriptor == -1) {
|
if (file_descriptor == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
* @return int
|
* @return int
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
int filesystem_read(string_t path, byte_t **file_content, off_t *file_size);
|
int filesystem_read(string_t path, byte_t **file_content, size_t *file_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Write the content to a file.
|
* @brief Write the content to a file.
|
||||||
@ -37,14 +37,13 @@ int filesystem_read(string_t path, byte_t **file_content, off_t *file_size);
|
|||||||
* @return int
|
* @return int
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
int filesystem_write(string_t path, byte_t *file_content, off_t file_size);
|
int filesystem_write(string_t path, byte_t *file_content, size_t file_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if a path exists.
|
* @brief Check if a path exists.
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path
|
||||||
* @return true
|
* @return bool
|
||||||
* @return false
|
|
||||||
* @since v3.1.0
|
* @since v3.1.0
|
||||||
*/
|
*/
|
||||||
bool filesystem_exists(string_t path);
|
bool filesystem_exists(string_t path);
|
||||||
|
@ -40,7 +40,7 @@ uint64_t hash(string_t key, size_t capacity) {
|
|||||||
memcpy(&m, message + offset, sizeof(uint64_t));
|
memcpy(&m, message + offset, sizeof(uint64_t));
|
||||||
v3 ^= m;
|
v3 ^= m;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
v0 = sip_round(v0, v1, v2, v3);
|
v0 = sip_round(v0, v1, v2, v3);
|
||||||
v1 = ROTATE_LEFT(v1, 13);
|
v1 = ROTATE_LEFT(v1, 13);
|
||||||
v2 = ROTATE_LEFT(v2, 16);
|
v2 = ROTATE_LEFT(v2, 16);
|
||||||
@ -49,7 +49,7 @@ uint64_t hash(string_t key, size_t capacity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
v2 ^= 0xff;
|
v2 ^= 0xff;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
v0 = sip_round(v0, v1, v2, v3);
|
v0 = sip_round(v0, v1, v2, v3);
|
||||||
v1 = ROTATE_LEFT(v1, 13);
|
v1 = ROTATE_LEFT(v1, 13);
|
||||||
v2 = ROTATE_LEFT(v2, 16);
|
v2 = ROTATE_LEFT(v2, 16);
|
||||||
@ -90,7 +90,7 @@ uint64_t hash(string_t key, size_t capacity) {
|
|||||||
|
|
||||||
v3 ^= m;
|
v3 ^= m;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
v0 = sip_round(v0, v1, v2, v3);
|
v0 = sip_round(v0, v1, v2, v3);
|
||||||
v1 = ROTATE_LEFT(v1, 13);
|
v1 = ROTATE_LEFT(v1, 13);
|
||||||
v2 = ROTATE_LEFT(v2, 16);
|
v2 = ROTATE_LEFT(v2, 16);
|
||||||
@ -100,7 +100,7 @@ uint64_t hash(string_t key, size_t capacity) {
|
|||||||
v0 ^= m;
|
v0 ^= m;
|
||||||
v2 ^= 0xff;
|
v2 ^= 0xff;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
v0 = sip_round(v0, v1, v2, v3);
|
v0 = sip_round(v0, v1, v2, v3);
|
||||||
v1 = ROTATE_LEFT(v1, 13);
|
v1 = ROTATE_LEFT(v1, 13);
|
||||||
v2 = ROTATE_LEFT(v2, 16);
|
v2 = ROTATE_LEFT(v2, 16);
|
||||||
|
@ -85,8 +85,7 @@ void *hash_map_get(struct hash_map *hash_map, string_t key);
|
|||||||
*
|
*
|
||||||
* @param hash_map
|
* @param hash_map
|
||||||
* @param key
|
* @param key
|
||||||
* @return true
|
* @return bool
|
||||||
* @return false
|
|
||||||
* @since v2.0.0
|
* @since v2.0.0
|
||||||
*/
|
*/
|
||||||
bool hash_map_contains_key(struct hash_map *hash_map, string_t key);
|
bool hash_map_contains_key(struct hash_map *hash_map, string_t key);
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
#include "mathematics.h"
|
#include "mathematics.h"
|
||||||
|
|
||||||
bool mathematics_equals(const float number1, const float number2) {
|
bool mathematics_equals(const float64_t number1, const float64_t number2) {
|
||||||
return (number1 - number2) < MATHEMATICS_FLOAT_PRECISION;
|
return (number1 - number2) < MATHEMATICS_DOUBLE_PRECISION;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long mathematics_absolute_value(const long long number) {
|
uint64_t mathematics_absolute_value(const int64_t number) {
|
||||||
if (number >= 0) {
|
if (number >= 0) {
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
return -number;
|
return -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long mathematics_pow(unsigned long long base, unsigned long long exponent) {
|
uint64_t mathematics_pow(uint64_t base, uint64_t exponent) {
|
||||||
return exponent == 0 ? 1 : base * mathematics_pow(base, exponent - 1);
|
return exponent == 0 ? 1 : base * mathematics_pow(base, exponent - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float mathematics_root(float number, unsigned int nth_root) {
|
float64_t mathematics_root(float64_t number, uint64_t nth_root) {
|
||||||
float result = number;
|
float64_t result = number;
|
||||||
float previous_result = 0;
|
float64_t previous_result = 0;
|
||||||
while (!mathematics_equals(result, previous_result)) {
|
while (!mathematics_equals(result, previous_result)) {
|
||||||
result = (((nth_root - 1) * previous_result) + (number / mathematics_pow(result, nth_root - 1))) / nth_root;
|
result = (((nth_root - 1) * previous_result) + (number / mathematics_pow(result, nth_root - 1))) / nth_root;
|
||||||
previous_result = result;
|
previous_result = result;
|
||||||
@ -25,11 +25,11 @@ float mathematics_root(float number, unsigned int nth_root) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float mathematics_square_root(float number) {
|
float64_t mathematics_square_root(float64_t number) {
|
||||||
return mathematics_root(number, 2);
|
return mathematics_root(number, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long mathematics_factorial(unsigned long long number) {
|
uint64_t mathematics_factorial(uint64_t number) {
|
||||||
return number == 0 ? 1 : number * mathematics_factorial(number - 1);
|
return number == 0 ? 1 : number * mathematics_factorial(number - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef __LIBCPROJECT_MATHEMATICS__
|
#ifndef __LIBCPROJECT_MATHEMATICS__
|
||||||
#define __LIBCPROJECT_MATHEMATICS__
|
#define __LIBCPROJECT_MATHEMATICS__
|
||||||
|
|
||||||
#define MATHEMATICS_FLOAT_PRECISION 0.00000001
|
#define MATHEMATICS_DOUBLE_PRECISION 0.0000000001
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -14,58 +14,57 @@
|
|||||||
*
|
*
|
||||||
* @param number1
|
* @param number1
|
||||||
* @param number2
|
* @param number2
|
||||||
* @return true
|
* @return bool
|
||||||
* @return false
|
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
bool mathematics_equals(const float number1, const float number2);
|
bool mathematics_equals(const float64_t number1, const float64_t number2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the absolute value of a number.
|
* @brief Get the absolute value of a number.
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* @return unsigned long long
|
* @return uint64_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
unsigned long long mathematics_absolute_value(const long long number);
|
uint64_t mathematics_absolute_value(const int64_t number);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calculates the power of a number.
|
* @brief Calculates the power of a number.
|
||||||
*
|
*
|
||||||
* @param base
|
* @param base
|
||||||
* @param exponent
|
* @param exponent
|
||||||
* @return unsigned long long
|
* @return uint64_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
unsigned long long mathematics_pow(unsigned long long base, unsigned long long exponent);
|
uint64_t mathematics_pow(uint64_t base, uint64_t exponent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calculates the nth root of a number.
|
* @brief Calculates the nth root of a number.
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* @param nth_root
|
* @param nth_root
|
||||||
* @return float
|
* @return float64_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
float mathematics_root(float number, unsigned int nth_root);
|
float64_t mathematics_root(float64_t number, uint64_t nth_root);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calculates the square root of a number using Heron's method.
|
* @brief Calculates the square root of a number using Heron's method.
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* @return float
|
* @return float64_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
float mathematics_square_root(float number);
|
float64_t mathematics_square_root(float64_t number);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calculates the factorial of a number.
|
* @brief Calculates the factorial of a number.
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* @return unsigned long long
|
* @return uint64_t
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
unsigned long long mathematics_factorial(unsigned long long number);
|
uint64_t mathematics_factorial(uint64_t number);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calulcates the opposite number (additive inverse).
|
* @brief Calulcates the opposite number (additive inverse).
|
||||||
|
@ -296,7 +296,7 @@ bool string_get_is_substring(const string_t string, const string_t substring) {
|
|||||||
return is_substring;
|
return is_substring;
|
||||||
}
|
}
|
||||||
|
|
||||||
string_t string_get_formatted_number(const long long number, string_t separator) {
|
string_t string_get_formatted_number(const int64_t number, string_t separator) {
|
||||||
string_t number_string_temp = convert_number_to_string(number);
|
string_t number_string_temp = convert_number_to_string(number);
|
||||||
string_t number_string = number_string_temp;
|
string_t number_string = number_string_temp;
|
||||||
bool is_negative = number_string_temp[0] == '-';
|
bool is_negative = number_string_temp[0] == '-';
|
||||||
@ -433,7 +433,7 @@ string_t string_pad_start(const string_t string, const string_t pad_string, size
|
|||||||
}
|
}
|
||||||
|
|
||||||
string_t string_zero_pad(uint64_t number, size_t places) {
|
string_t string_zero_pad(uint64_t number, size_t places) {
|
||||||
string_t number_string = convert_number_to_string((long long)number);
|
string_t number_string = convert_number_to_string((int64_t)number);
|
||||||
string_t pad_string = string_copy("0");
|
string_t pad_string = string_copy("0");
|
||||||
string_t result = string_pad_start(number_string, pad_string, places);
|
string_t result = string_pad_start(number_string, pad_string, places);
|
||||||
free(pad_string);
|
free(pad_string);
|
||||||
|
@ -232,7 +232,7 @@ bool string_get_is_substring(const string_t string, const string_t substring);
|
|||||||
* @endcode
|
* @endcode
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
*/
|
*/
|
||||||
string_t string_get_formatted_number(const long long number, string_t separator);
|
string_t string_get_formatted_number(const int64_t number, string_t separator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a pointer to the last occurrence of character in the string.
|
* @brief Returns a pointer to the last occurrence of character in the string.
|
||||||
|
@ -21,6 +21,66 @@ string_t terminal_input() {
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void terminal_print_int(void* value) {
|
||||||
|
printf("%d", *(int*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_bool(void* value) {
|
||||||
|
printf("%s", *(bool*)value ? "true" : "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_long(void* value) {
|
||||||
|
printf("%ld", *(long*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_unsigned_long(void* value) {
|
||||||
|
printf("%lu", *(unsigned long*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_float(void* value) {
|
||||||
|
printf("%f", *(float*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_double(void* value) {
|
||||||
|
printf("%f", *(double*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_int8_t(void* value) {
|
||||||
|
printf("%d", *(int8_t*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_int16_t(void* value) {
|
||||||
|
printf("%d", *(int16_t*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_int32_t(void* value) {
|
||||||
|
printf("%d", *(int32_t*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_int64_t(void* value) {
|
||||||
|
printf("%ld", *(int64_t*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_uint8_t(void* value) {
|
||||||
|
printf("%u", *(uint8_t*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_uint16_t(void* value) {
|
||||||
|
printf("%u", *(uint16_t*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_uint32_t(void* value) {
|
||||||
|
printf("%u", *(uint32_t*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_uint64_t(void* value) {
|
||||||
|
printf("%lu", *(uint64_t*)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void terminal_print_char(void* value) {
|
||||||
|
printf("%c", *(string_t)value);
|
||||||
|
}
|
||||||
|
|
||||||
void terminal_print_array(void* array, size_t array_size, size_t element_size, void (*print_element)(void*)) {
|
void terminal_print_array(void* array, size_t array_size, size_t element_size, void (*print_element)(void*)) {
|
||||||
printf("[");
|
printf("[");
|
||||||
for (size_t index = 0; index < array_size; index++) {
|
for (size_t index = 0; index < array_size; index++) {
|
||||||
@ -34,22 +94,6 @@ void terminal_print_array(void* array, size_t array_size, size_t element_size, v
|
|||||||
printf("]\n");
|
printf("]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminal_print_int(void* value) {
|
|
||||||
printf("%d", *(int*)value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void terminal_print_long(void* value) {
|
|
||||||
printf("%ld", *(long*)value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void terminal_print_unsigned_long(void* value) {
|
|
||||||
printf("%lu", *(unsigned long*)value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void terminal_print_char(void* value) {
|
|
||||||
printf("%c", *(string_t)value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void terminal_print_string(void* value) {
|
void terminal_print_string(void* value) {
|
||||||
printf("%s", (string_t)value);
|
printf("%s", (string_t)value);
|
||||||
}
|
}
|
||||||
@ -64,7 +108,7 @@ void terminal_print_stack(struct stack* stack, void (*print_element)(void*)) {
|
|||||||
while (node_current != NULL) {
|
while (node_current != NULL) {
|
||||||
printf("|\t");
|
printf("|\t");
|
||||||
void* element = node_current->data;
|
void* element = node_current->data;
|
||||||
print_element(&element);
|
print_element(element);
|
||||||
node_current = node_current->next;
|
node_current = node_current->next;
|
||||||
printf("\t|\n");
|
printf("\t|\n");
|
||||||
}
|
}
|
||||||
@ -80,7 +124,7 @@ void terminal_print_queue(struct queue* queue, void (*print_element)(void*)) {
|
|||||||
while (node_current != NULL) {
|
while (node_current != NULL) {
|
||||||
printf("|\t");
|
printf("|\t");
|
||||||
void* element = node_current->data;
|
void* element = node_current->data;
|
||||||
print_element(&element);
|
print_element(element);
|
||||||
node_current = node_current->next;
|
node_current = node_current->next;
|
||||||
printf("\t|\n");
|
printf("\t|\n");
|
||||||
}
|
}
|
||||||
@ -96,7 +140,7 @@ void terminal_print_linked_list(struct linked_list* linked_list, void (*print_el
|
|||||||
while (node_current != NULL) {
|
while (node_current != NULL) {
|
||||||
void* element = (string_t)node_current->data;
|
void* element = (string_t)node_current->data;
|
||||||
node_current = node_current->next;
|
node_current = node_current->next;
|
||||||
print_element(&element);
|
print_element(element);
|
||||||
printf(" -> ");
|
printf(" -> ");
|
||||||
}
|
}
|
||||||
printf("NULL\n");
|
printf("NULL\n");
|
||||||
@ -116,12 +160,21 @@ void terminal_print_hash_map(struct hash_map* hash_map, void (*print_element)(vo
|
|||||||
printf("\t\"");
|
printf("\t\"");
|
||||||
terminal_print_string(key);
|
terminal_print_string(key);
|
||||||
printf("\" -> ");
|
printf("\" -> ");
|
||||||
print_element(&value);
|
print_element(value);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
printf("}\n");
|
printf("}\n");
|
||||||
|
free(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminal_print_array_list(struct array_list* list, void (*print_element)(void*)) {
|
void terminal_print_array_list(struct array_list* list, void (*print_element)(void*)) {
|
||||||
terminal_print_array(list->data, list->size, sizeof(void*), print_element);
|
printf("[");
|
||||||
|
for (size_t index = 0; index < list->size; index++) {
|
||||||
|
void* element = list->data[index];
|
||||||
|
print_element(element);
|
||||||
|
if (index < list->size - 1) {
|
||||||
|
printf(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("]\n");
|
||||||
}
|
}
|
||||||
|
110
lib/terminal.h
110
lib/terminal.h
@ -23,17 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
string_t terminal_input();
|
string_t terminal_input();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Print an array.
|
|
||||||
*
|
|
||||||
* @param array
|
|
||||||
* @param array_size
|
|
||||||
* @param element_size
|
|
||||||
* @param print_element
|
|
||||||
* @since v1.0.0
|
|
||||||
*/
|
|
||||||
void terminal_print_array(void* array, size_t array_size, size_t element_size, void (*print_element)(void*));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Print a int.
|
* @brief Print a int.
|
||||||
*
|
*
|
||||||
@ -42,6 +31,14 @@ void terminal_print_array(void* array, size_t array_size, size_t element_size, v
|
|||||||
*/
|
*/
|
||||||
void terminal_print_int(void* value);
|
void terminal_print_int(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a boolean.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_bool(void* value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Print a long.
|
* @brief Print a long.
|
||||||
*
|
*
|
||||||
@ -58,6 +55,86 @@ void terminal_print_long(void* value);
|
|||||||
*/
|
*/
|
||||||
void terminal_print_unsigned_long(void* value);
|
void terminal_print_unsigned_long(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a float.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_float(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a double.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_double(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a int8_t.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_int8_t(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a int16_t.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_int16_t(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a int32_t.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_int32_t(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a int64_t.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_int64_t(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a uint8_t.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_uint8_t(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a uint16_t.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_uint16_t(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a uint32_t.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_uint32_t(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print a uint64_t.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @since v5.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_uint64_t(void* value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Print a char.
|
* @brief Print a char.
|
||||||
*
|
*
|
||||||
@ -66,6 +143,17 @@ void terminal_print_unsigned_long(void* value);
|
|||||||
*/
|
*/
|
||||||
void terminal_print_char(void* value);
|
void terminal_print_char(void* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print an array.
|
||||||
|
*
|
||||||
|
* @param array
|
||||||
|
* @param array_size
|
||||||
|
* @param element_size
|
||||||
|
* @param print_element
|
||||||
|
* @since v1.0.0
|
||||||
|
*/
|
||||||
|
void terminal_print_array(void* array, size_t array_size, size_t element_size, void (*print_element)(void*));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Print a string.
|
* @brief Print a string.
|
||||||
*
|
*
|
||||||
|
@ -7,4 +7,7 @@ typedef uint8_t byte_t;
|
|||||||
|
|
||||||
typedef char* string_t;
|
typedef char* string_t;
|
||||||
|
|
||||||
|
typedef float float32_t;
|
||||||
|
typedef double float64_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define __LIBCPROJECT__
|
#define __LIBCPROJECT__
|
||||||
|
|
||||||
#include "lib/array_list.h"
|
#include "lib/array_list.h"
|
||||||
|
#include "lib/assert.h"
|
||||||
#include "lib/character.h"
|
#include "lib/character.h"
|
||||||
#include "lib/convert.h"
|
#include "lib/convert.h"
|
||||||
#include "lib/date.h"
|
#include "lib/date.h"
|
||||||
|
119
main.c
119
main.c
@ -4,8 +4,123 @@
|
|||||||
#include "libcproject.h"
|
#include "libcproject.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
int integer = 5;
|
||||||
|
terminal_print_int(&integer);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
bool boolean = true;
|
||||||
|
printf("terminal_print_bool: ");
|
||||||
|
terminal_print_bool(&boolean);
|
||||||
|
printf(", ");
|
||||||
|
boolean = false;
|
||||||
|
terminal_print_bool(&boolean);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
long integer_long = 5;
|
||||||
|
printf("terminal_print_long: ");
|
||||||
|
terminal_print_long(&integer_long);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
unsigned long integer_unsigned_long = 5;
|
||||||
|
printf("terminal_print_unsigned_long: ");
|
||||||
|
terminal_print_unsigned_long(&integer_unsigned_long);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
float floating_point = 5.5;
|
||||||
|
printf("terminal_print_float: ");
|
||||||
|
terminal_print_float(&floating_point);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
double floating_point_double = 5.5;
|
||||||
|
printf("terminal_print_double: ");
|
||||||
|
terminal_print_double(&floating_point_double);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
int8_t integer_8 = 5;
|
||||||
|
printf("terminal_print_int8_t: ");
|
||||||
|
terminal_print_int8_t(&integer_8);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
int16_t integer_16 = 5;
|
||||||
|
printf("terminal_print_int16_t: ");
|
||||||
|
terminal_print_int16_t(&integer_16);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
int32_t integer_32 = 5;
|
||||||
|
printf("terminal_print_int32_t: ");
|
||||||
|
terminal_print_int32_t(&integer_32);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
int64_t integer_64 = 5;
|
||||||
|
printf("terminal_print_int64_t: ");
|
||||||
|
terminal_print_int64_t(&integer_64);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
uint8_t integer_unsigned_8 = 5;
|
||||||
|
printf("terminal_print_uint8_t: ");
|
||||||
|
terminal_print_uint8_t(&integer_unsigned_8);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
uint16_t integer_unsigned_16 = 5;
|
||||||
|
printf("terminal_print_uint16_t: ");
|
||||||
|
terminal_print_uint16_t(&integer_unsigned_16);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
uint32_t integer_unsigned_32 = 5;
|
||||||
|
printf("terminal_print_uint32_t: ");
|
||||||
|
terminal_print_uint32_t(&integer_unsigned_32);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
uint64_t integer_unsigned_64 = 5;
|
||||||
|
printf("terminal_print_uint64_t: ");
|
||||||
|
terminal_print_uint64_t(&integer_unsigned_64);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
char character = 'c';
|
||||||
|
printf("terminal_print_char: ");
|
||||||
|
terminal_print_char(&character);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
int array[] = {1, 2, 3, 4, 5};
|
||||||
|
printf("terminal_print_array: ");
|
||||||
|
terminal_print_array(array, 5, sizeof(int), terminal_print_int);
|
||||||
|
|
||||||
string_t string = "Hello, world!";
|
string_t string = "Hello, world!";
|
||||||
printf("%s\n", string);
|
printf("terminal_print_string: ");
|
||||||
printf("string_length = %ld\n", string_get_length(string));
|
terminal_print_string(string);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
struct stack* stack = stack_initialization();
|
||||||
|
stack_push(stack, &integer);
|
||||||
|
printf("terminal_print_stack: ");
|
||||||
|
terminal_print_stack(stack, terminal_print_int);
|
||||||
|
stack_free(stack);
|
||||||
|
|
||||||
|
struct queue* queue = queue_initialization();
|
||||||
|
queue_push(queue, &integer);
|
||||||
|
printf("terminal_print_queue: ");
|
||||||
|
terminal_print_queue(queue, terminal_print_int);
|
||||||
|
queue_free(queue);
|
||||||
|
|
||||||
|
struct linked_list* linked_list = linked_list_initialization();
|
||||||
|
linked_list_add_after_last(linked_list, string);
|
||||||
|
linked_list_add_after_last(linked_list, string);
|
||||||
|
printf("terminal_print_linked_list: ");
|
||||||
|
terminal_print_linked_list(linked_list, terminal_print_string);
|
||||||
|
linked_list_free(linked_list);
|
||||||
|
|
||||||
|
struct hash_map* hash_map = hash_map_initialization();
|
||||||
|
hash_map_add(hash_map, "key", &integer);
|
||||||
|
printf("terminal_print_hash_map: ");
|
||||||
|
terminal_print_hash_map(hash_map, terminal_print_int);
|
||||||
|
hash_map_free(hash_map);
|
||||||
|
|
||||||
|
struct array_list* array_list = array_list_initialization();
|
||||||
|
array_list_add(array_list, &integer);
|
||||||
|
array_list_add(array_list, &integer);
|
||||||
|
printf("terminal_print_array_list: ");
|
||||||
|
terminal_print_array_list(array_list, terminal_print_int);
|
||||||
|
array_list_free(array_list);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "libcproject.h"
|
#include "libcproject.h"
|
||||||
#include "test.h"
|
|
||||||
|
|
||||||
void character_test();
|
void character_test();
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "libcproject.h"
|
#include "libcproject.h"
|
||||||
#include "test.h"
|
|
||||||
|
|
||||||
void convert_test();
|
void convert_test();
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "libcproject.h"
|
#include "libcproject.h"
|
||||||
#include "test.h"
|
|
||||||
|
|
||||||
void date_test();
|
void date_test();
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "libcproject.h"
|
#include "libcproject.h"
|
||||||
#include "test.h"
|
|
||||||
|
|
||||||
void string_test();
|
void string_test();
|
||||||
|
|
||||||
|
14
test/test.h
14
test/test.h
@ -1,14 +0,0 @@
|
|||||||
#ifndef __TEST__
|
|
||||||
#define __TEST__
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "libcproject.h"
|
|
||||||
|
|
||||||
bool assert_string_equal(const string_t actual, const string_t expected);
|
|
||||||
|
|
||||||
bool assert_string_not_equal(const string_t actual, const string_t expected);
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user