1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2024-10-05 12:06:09 +02:00

feat: add assert module

This commit is contained in:
Théo LUDWIG 2024-09-25 14:57:34 +02:00
parent 1be12c2a97
commit 336bbf6197
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
12 changed files with 38 additions and 29 deletions

View File

@ -1,7 +1,7 @@
#include "test.h"
#include "assert.h"
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);
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) {
if (strcmp(expected, actual) == 0) {
if (string_equals(actual, expected)) {
printf("FAIL: expected = \"%s\" ; actual = \"%s\"\n", expected, actual);
return false;
}

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);

View File

@ -2,6 +2,7 @@
#define __LIBCPROJECT__
#include "lib/array_list.h"
#include "lib/assert.h"
#include "lib/character.h"
#include "lib/convert.h"
#include "lib/date.h"

View File

@ -6,7 +6,6 @@
#include <stdlib.h>
#include "libcproject.h"
#include "test.h"
void character_test();

View File

@ -6,7 +6,6 @@
#include <stdlib.h>
#include "libcproject.h"
#include "test.h"
void convert_test();

View File

@ -4,7 +4,6 @@
#include <assert.h>
#include "libcproject.h"
#include "test.h"
void date_test();

View File

@ -6,7 +6,6 @@
#include <stdlib.h>
#include "libcproject.h"
#include "test.h"
void string_test();

View File

@ -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