1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2025-05-21 23:21:15 +02:00

feat: add assert module

This commit is contained in:
2024-09-25 14:57:34 +02:00
parent 1be12c2a97
commit 336bbf6197
12 changed files with 38 additions and 29 deletions

17
lib/assert.c Normal file
View File

@ -0,0 +1,17 @@
#include "assert.h"
bool assert_string_equal(const string_t actual, const string_t expected) {
if (!string_equals(actual, expected)) {
printf("FAIL: expected = \"%s\" ; actual = \"%s\"\n", expected, actual);
return false;
}
return true;
}
bool assert_string_not_equal(const string_t actual, const string_t expected) {
if (string_equals(actual, expected)) {
printf("FAIL: expected = \"%s\" ; actual = \"%s\"\n", expected, actual);
return false;
}
return true;
}

30
lib/assert.h Normal file
View 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

View File

@ -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').
*
* @param character
* @return true
* @return false
* @return bool
* @since v1.0.0
*/
bool character_get_is_digit(const char character);

View File

@ -43,8 +43,7 @@ int filesystem_write(string_t path, byte_t *file_content, size_t file_size);
* @brief Check if a path exists.
*
* @param path
* @return true
* @return false
* @return bool
* @since v3.1.0
*/
bool filesystem_exists(string_t path);

View File

@ -85,8 +85,7 @@ void *hash_map_get(struct hash_map *hash_map, string_t key);
*
* @param hash_map
* @param key
* @return true
* @return false
* @return bool
* @since v2.0.0
*/
bool hash_map_contains_key(struct hash_map *hash_map, string_t key);

View File

@ -14,8 +14,7 @@
*
* @param number1
* @param number2
* @return true
* @return false
* @return bool
* @since v1.0.0
*/
bool mathematics_equals(const float64_t number1, const float64_t number2);