diff --git a/.github/workflows/clang-build.yml b/.github/workflows/clang-build.yml
new file mode 100644
index 0000000..e2f1f56
--- /dev/null
+++ b/.github/workflows/clang-build.yml
@@ -0,0 +1,19 @@
+name: clang-build
+on: [push,pull_request,workflow_dispatch]
+
+jobs:
+ clang-build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Install Clang
+ run: sudo apt update && sudo apt install -y clang
+
+ - name: Build Datum
+ run: |
+ make clean all
+
+ - name: Run unit tests
+ run: |
+ ./test_vector && ./test_map && ./test_bigint
\ No newline at end of file
diff --git a/.github/workflows/datum.yml b/.github/workflows/gcc-build.yml
similarity index 59%
rename from .github/workflows/datum.yml
rename to .github/workflows/gcc-build.yml
index 4f25837..b277691 100644
--- a/.github/workflows/datum.yml
+++ b/.github/workflows/gcc-build.yml
@@ -1,17 +1,16 @@
-name: datum
-on:
- push:
- branch: [master]
- workflow_dispatch:
+name: gcc-build
+on: [push,pull_request,workflow_dispatch]
jobs:
- build:
+ gcc-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
+
- name: Build Datum
run: |
make clean all
+
- name: Run unit tests
run: |
- ./test_vector && ./test_map
\ No newline at end of file
+ ./test_vector && ./test_map && ./test_bigint
\ No newline at end of file
diff --git a/README.md b/README.md
index 49ea15e..95b1dc5 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,8 @@
Datum
Collection of dynamic and generic data structures.
-[](https://github.com/ceticamarco/datum/actions/workflows/datum.yml)
+[](https://github.com/ceticamarco/datum/actions/workflows/gcc-build.yml)
+[](https://github.com/ceticamarco/datum/actions/workflows/clang-build.yml)
Datum is a collection of dynamic and generic data structures implemented from scratch in C with no external dependencies beyond
@@ -98,19 +99,18 @@ int main(void) {
### `BigInt` usage
```c
-#include
#include "src/bigint.h"
/*
- * Compile with: gcc main.c src/bigint.c
+ * Compile with: gcc -O3 main.c src/bigint.c src/vector.c
* Output: 20000! = 1819206320230345134827641...
- * Time: real 0m5.482s user 0m5.453s sys 0m0.017
+ * Time: 4.01s user 0.00s system 99% cpu 4.021 total
*/
int main(void) {
const int n = 20000;
bigint_t *fact = bigint_from_int(1).value.number;
- for (int idx = 2; idx<=n; idx++) {
+ for (int idx = 2; idx <= n; idx++) {
bigint_t *big_idx = bigint_from_int(idx).value.number;
bigint_t *partial_fact = bigint_prod(fact, big_idx).value.number;
@@ -119,17 +119,13 @@ int main(void) {
fact = partial_fact;
}
- printf("%d! = ", n);
- bigint_print(fact);
- printf("\n");
+ bigint_printf("%d! = %B\n", n, fact);
bigint_destroy(fact);
return 0;
}
```
-
-
For a more exhaustive example, refer to the `usage.c` file. There, you will find a program with proper error management
and a sample usage for every available method. To run it, first issue the following command:
@@ -144,12 +140,13 @@ For additional details about this library (internal design, memory
management, data ownership, etc.) go to the [docs folder](/docs).
## Unit tests
-Datum provides some unit tests for both the `Vector` and the `Map` data types. To run them, you can issue the following commands:
+Datum provides some unit tests for `Vector`, `Map` and `BigInt`. To run them, you can issue the following commands:
```sh
$ make clean all
$ ./test_vector
$ ./test_map
+$ ./test_bigint
```
## License
diff --git a/src/bigint.c b/src/bigint.c
index 89a042f..448fdf6 100644
--- a/src/bigint.c
+++ b/src/bigint.c
@@ -1854,4 +1854,4 @@ bigint_result_t bigint_printf(const char *format, ...) {
SET_MSG(result, "Printf completed successfully");
return result;
-}
\ No newline at end of file
+}
diff --git a/src/bigint.h b/src/bigint.h
index 984e0fa..25e119d 100644
--- a/src/bigint.h
+++ b/src/bigint.h
@@ -61,4 +61,4 @@ bigint_result_t bigint_printf(const char *format, ...);
}
#endif
-#endif
\ No newline at end of file
+#endif
diff --git a/src/map.c b/src/map.c
index 88a3887..542065c 100644
--- a/src/map.c
+++ b/src/map.c
@@ -37,7 +37,7 @@ uint64_t hash_key(const char *key) {
*
* Returns a map_result_t data type containing a new hash map
*/
-map_result_t map_new() {
+map_result_t map_new(void) {
map_result_t result = {0};
map_t *map = malloc(sizeof(map_t));
diff --git a/src/map.h b/src/map.h
index 704b820..a7f3643 100644
--- a/src/map.h
+++ b/src/map.h
@@ -53,7 +53,7 @@ typedef struct {
extern "C" {
#endif
-map_result_t map_new();
+map_result_t map_new(void);
map_result_t map_add(map_t *map, const char *key, void *value);
map_result_t map_get(const map_t *map, const char *key);
map_result_t map_remove(map_t *map, const char *key);
diff --git a/tests/test_bigint.c b/tests/test_bigint.c
index 711a446..0cc5aad 100644
--- a/tests/test_bigint.c
+++ b/tests/test_bigint.c
@@ -16,15 +16,21 @@
#include "../src/bigint.h"
static void bigint_eq(const bigint_t *number, const char *expected) {
- bigint_result_t to_str = bigint_to_string(number);
- assert(to_str.status == BIGINT_OK);
- assert(!strcmp(to_str.value.string_num, expected));
+ bigint_result_t exp_num_res = bigint_from_string(expected);
+ assert(exp_num_res.status == BIGINT_OK);
+ bigint_t *exp_num = exp_num_res.value.number;
+
+ bigint_result_t cmp_res = bigint_compare(number, exp_num);
+ assert(cmp_res.status == BIGINT_OK);
- free(to_str.value.string_num);
+ const int8_t cmp = cmp_res.value.compare_status;
+ assert(cmp == 0);
+
+ bigint_destroy(exp_num);
}
// Test creating big integers from int
-void test_bigint_from_int() {
+void test_bigint_from_int(void) {
bigint_result_t res = bigint_from_int(0);
assert(res.status == BIGINT_OK);
@@ -43,21 +49,333 @@ void test_bigint_from_int() {
}
// Test creating big integers from string
-void test_bigint_from_string() {
+void test_bigint_from_string(void) {
bigint_result_t res = bigint_from_string("00000123");
assert(res.status == BIGINT_OK);
bigint_eq(res.value.number, "123");
bigint_destroy(res.value.number);
+
+ res = bigint_from_string("-00000456789");
+ assert(res.status == BIGINT_OK);
+ bigint_eq(res.value.number, "-456789");
+ bigint_destroy(res.value.number);
}
+// Test sum between big integers
+void test_bigint_add(void) {
+ bigint_result_t x = bigint_from_int(123);
+ bigint_result_t y = bigint_from_int(456);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t sum = bigint_add(x.value.number, y.value.number);
+ assert(sum.status == BIGINT_OK);
+ bigint_eq(sum.value.number, "579");
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+ bigint_destroy(sum.value.number);
+}
+
+// Test difference between big numbers
+void test_bigint_sub(void) {
+ bigint_result_t x = bigint_from_int(456);
+ bigint_result_t y = bigint_from_int(123);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t diff = bigint_sub(x.value.number, y.value.number);
+ assert(diff.status == BIGINT_OK);
+ bigint_eq(diff.value.number, "333");
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+ bigint_destroy(diff.value.number);
+}
+
+// Test difference between big numbers with negative result
+void test_bigint_sub_neg(void) {
+ bigint_result_t x = bigint_from_int(123);
+ bigint_result_t y = bigint_from_int(456);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t diff = bigint_sub(x.value.number, y.value.number);
+ assert(diff.status == BIGINT_OK);
+ bigint_eq(diff.value.number, "-333");
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+ bigint_destroy(diff.value.number);
+}
+
+// Test difference between mixed big numbers
+void test_bigint_sub_mixed(void) {
+ bigint_result_t x = bigint_from_int(456);
+ bigint_result_t y = bigint_from_int(-123);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t diff = bigint_sub(x.value.number, y.value.number);
+ assert(diff.status == BIGINT_OK);
+ bigint_eq(diff.value.number, "579");
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+ bigint_destroy(diff.value.number);
+}
+
+// Test product between big numbers
+void test_bigint_prod(void) {
+ bigint_result_t x = bigint_from_int(1234);
+ bigint_result_t y = bigint_from_int(56789);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t prod = bigint_prod(x.value.number, y.value.number);
+ assert(prod.status == BIGINT_OK);
+ bigint_eq(prod.value.number, "70077626");
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+ bigint_destroy(prod.value.number);
+}
+
+// Test product between mixed negative big numbers
+void test_bigint_prod_mixed(void) {
+ bigint_result_t x = bigint_from_int(-1234);
+ bigint_result_t y = bigint_from_int(56789);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t prod = bigint_prod(x.value.number, y.value.number);
+ assert(prod.status == BIGINT_OK);
+ bigint_eq(prod.value.number, "-70077626");
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+ bigint_destroy(prod.value.number);
+}
+
+// Test product between negative big numbers
+void test_bigint_prod_neg(void) {
+ bigint_result_t x = bigint_from_int(-1234);
+ bigint_result_t y = bigint_from_int(-56789);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t prod = bigint_prod(x.value.number, y.value.number);
+ assert(prod.status == BIGINT_OK);
+ bigint_eq(prod.value.number, "70077626");
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+ bigint_destroy(prod.value.number);
+}
+
+// Test division between big numbers
+void test_bigint_div(void) {
+ bigint_result_t x = bigint_from_int(100);
+ bigint_result_t y = bigint_from_int(2);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t div = bigint_divmod(x.value.number, y.value.number);
+ assert(div.status == BIGINT_OK);
+
+ bigint_t* const quotient = div.value.division.quotient;
+ bigint_t* const remainder = div.value.division.remainder;
+
+ bigint_eq(quotient, "50");
+ bigint_eq(remainder, "0");
+
+ bigint_destroy(quotient);
+ bigint_destroy(remainder);
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+}
+
+// Test division between big numbers with negative dividend
+// This library follows C-style divison such that sign(remainder) = sign(dividend)
+void test_bigint_div_dividend(void) {
+ bigint_result_t x = bigint_from_int(-100);
+ bigint_result_t y = bigint_from_int(3);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t div = bigint_divmod(x.value.number, y.value.number);
+ assert(div.status == BIGINT_OK);
+
+ bigint_t* const quotient = div.value.division.quotient;
+ bigint_t* const remainder = div.value.division.remainder;
+
+ bigint_eq(quotient, "-33");
+ bigint_eq(remainder, "-1");
+
+ bigint_destroy(quotient);
+ bigint_destroy(remainder);
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+}
+
+// Test division between big numbers with negative divisor
+// This library follows C-style divison such that sign(remainder) = sign(dividend)
+void test_bigint_div_divisor(void) {
+ bigint_result_t x = bigint_from_int(13);
+ bigint_result_t y = bigint_from_int(-4);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t div = bigint_divmod(x.value.number, y.value.number);
+ assert(div.status == BIGINT_OK);
+
+ bigint_t* const quotient = div.value.division.quotient;
+ bigint_t* const remainder = div.value.division.remainder;
+
+ bigint_eq(quotient, "-3");
+ bigint_eq(remainder, "1");
+
+ bigint_destroy(quotient);
+ bigint_destroy(remainder);
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+}
+
+// Test division between big numbers with negative numbers
+// This library follows C-style divison such that sign(remainder) = sign(dividend)
+void test_bigint_div_neg(void) {
+ bigint_result_t x = bigint_from_int(-100);
+ bigint_result_t y = bigint_from_int(-3);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t div = bigint_divmod(x.value.number, y.value.number);
+ assert(div.status == BIGINT_OK);
+
+ bigint_t* const quotient = div.value.division.quotient;
+ bigint_t* const remainder = div.value.division.remainder;
+
+ bigint_eq(quotient, "33");
+ bigint_eq(remainder, "-1");
+
+ bigint_destroy(quotient);
+ bigint_destroy(remainder);
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+}
+
+// Test division by zero
+void test_bigint_div_by_zero(void) {
+ bigint_result_t x = bigint_from_int(-100);
+ bigint_result_t y = bigint_from_int(0);
+
+ assert(x.status == BIGINT_OK && y.status == BIGINT_OK);
+
+ bigint_result_t div = bigint_divmod(x.value.number, y.value.number);
+ assert(div.status == BIGINT_ERR_DIV_BY_ZERO);
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+}
+
+// Test cloning of big numbers
+void test_bigint_clone(void) {
+ bigint_result_t x = bigint_from_string("0010101010");
+
+ assert(x.status == BIGINT_OK);
+
+ bigint_result_t cloned = bigint_clone(x.value.number);
+ assert(cloned.status == BIGINT_OK);
+
+ bigint_eq(cloned.value.number, "10101010");
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(cloned.value.number);
+}
+
+// Test comparison between equal numbers
+void test_bigint_compare_eq(void) {
+ bigint_result_t x = bigint_from_int(123);
+ bigint_result_t y = bigint_from_int(123);
+
+ assert(x.status == BIGINT_OK);
+ assert(y.status == BIGINT_OK);
+
+ bigint_result_t cmp_res = bigint_compare(x.value.number, y.value.number);
+ assert(cmp_res.status == BIGINT_OK);
+
+ const int8_t cmp = cmp_res.value.compare_status;
+ assert(cmp == 0);
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+}
+
+// Test comparison between numbers (less than)
+void test_bigint_compare_lt(void) {
+ bigint_result_t x = bigint_from_int(-123);
+ bigint_result_t y = bigint_from_int(0);
+
+ assert(x.status == BIGINT_OK);
+ assert(y.status == BIGINT_OK);
+
+ bigint_result_t cmp_res = bigint_compare(x.value.number, y.value.number);
+ assert(cmp_res.status == BIGINT_OK);
+
+ const int8_t cmp = cmp_res.value.compare_status;
+ assert(cmp == -1);
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+}
+
+// Test comparison between numbers (greater than)
+void test_bigint_compare_gt(void) {
+ bigint_result_t x = bigint_from_int(123);
+ bigint_result_t y = bigint_from_int(-5);
+
+ assert(x.status == BIGINT_OK);
+ assert(y.status == BIGINT_OK);
+
+ bigint_result_t cmp_res = bigint_compare(x.value.number, y.value.number);
+ assert(cmp_res.status == BIGINT_OK);
+
+ const int8_t cmp = cmp_res.value.compare_status;
+ assert(cmp == 1);
+
+ bigint_destroy(x.value.number);
+ bigint_destroy(y.value.number);
+}
+
+
int main(void) {
printf("=== Running BigInt unit tests ===\n\n");
TEST(bigint_from_int);
TEST(bigint_from_string);
+ TEST(bigint_add);
+ TEST(bigint_sub);
+ TEST(bigint_sub_neg);
+ TEST(bigint_sub_mixed);
+ TEST(bigint_prod);
+ TEST(bigint_prod_mixed);
+ TEST(bigint_prod_neg);
+ TEST(bigint_div);
+ TEST(bigint_div_dividend);
+ TEST(bigint_div_divisor);
+ TEST(bigint_div_neg);
+ TEST(bigint_div_by_zero);
+ TEST(bigint_clone);
+ TEST(bigint_compare_eq);
+ TEST(bigint_compare_lt);
+ TEST(bigint_compare_gt);
printf("\n=== All tests passed ===\n");
return 0;
-}
\ No newline at end of file
+}
diff --git a/tests/test_map.c b/tests/test_map.c
index 3a936f5..47085b9 100644
--- a/tests/test_map.c
+++ b/tests/test_map.c
@@ -15,7 +15,7 @@
#include "../src/map.h"
// Create a new map
-void test_map_new() {
+void test_map_new(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -27,7 +27,7 @@ void test_map_new() {
}
// Add elements to map
-void test_map_add() {
+void test_map_add(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -47,7 +47,7 @@ void test_map_add() {
}
// Add multiple elements to the map
-void test_map_add_multiple() {
+void test_map_add_multiple(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -68,7 +68,7 @@ void test_map_add_multiple() {
}
// Get map element
-void test_map_get() {
+void test_map_get(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -85,7 +85,7 @@ void test_map_get() {
}
// Get non-existing key from map
-void test_map_get_invalid() {
+void test_map_get_invalid(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -98,7 +98,7 @@ void test_map_get_invalid() {
}
// Map with heterogeneous types
-void test_map_mixed() {
+void test_map_mixed(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -126,7 +126,7 @@ void test_map_mixed() {
}
// Update existing map key
-void test_map_update() {
+void test_map_update(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -149,7 +149,7 @@ void test_map_update() {
}
// Remove an element from map
-void test_map_remove() {
+void test_map_remove(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -177,7 +177,7 @@ void test_map_remove() {
}
// Remove non-existing key from map
-void test_map_remove_invalid() {
+void test_map_remove_invalid(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -190,7 +190,7 @@ void test_map_remove_invalid() {
}
// Clear the map
-void test_map_clear() {
+void test_map_clear(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -212,7 +212,7 @@ void test_map_clear() {
}
// Clear empty map
-void test_map_clear_empty() {
+void test_map_clear_empty(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -226,7 +226,7 @@ void test_map_clear_empty() {
}
// Multiple operations in sequence (add, update, delete and clear)
-void test_map_sequence() {
+void test_map_sequence(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -266,7 +266,7 @@ typedef struct {
short age;
} Person;
-void test_map_struct() {
+void test_map_struct(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
@@ -298,7 +298,7 @@ void test_map_struct() {
}
// Test map capacity tracking
-void test_map_cap() {
+void test_map_cap(void) {
map_result_t res = map_new();
assert(res.status == MAP_OK);
diff --git a/tests/test_vector.c b/tests/test_vector.c
index fd1ca59..875c9cf 100644
--- a/tests/test_vector.c
+++ b/tests/test_vector.c
@@ -15,7 +15,7 @@
#include "../src/vector.h"
// Create a new vector
-void test_vector_new() {
+void test_vector_new(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -27,14 +27,14 @@ void test_vector_new() {
}
// Create a vector with zero capacity
-void test_vector_new_zcap() {
+void test_vector_new_zcap(void) {
vector_result_t res = vector_new(0, sizeof(int));
assert(res.status == VECTOR_ERR_ALLOCATE);
}
// Push elements to vector
-void test_vector_push() {
+void test_vector_push(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -54,7 +54,7 @@ void test_vector_push() {
}
// Trigger vector reallocation
-void test_vector_push_realloc() {
+void test_vector_push_realloc(void) {
vector_result_t res = vector_new(1, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -72,7 +72,7 @@ void test_vector_push_realloc() {
}
// Get vector elements
-void test_vector_get() {
+void test_vector_get(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -89,7 +89,7 @@ void test_vector_get() {
}
// Test out of bounds
-void test_vector_get_ofb() {
+void test_vector_get_ofb(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -119,7 +119,7 @@ vector_order_t cmp_int_desc(const void *x, const void *y) {
return cmp_int_asc(y, x);
}
-void test_vector_sort_int_asc() {
+void test_vector_sort_int_asc(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -142,7 +142,7 @@ void test_vector_sort_int_asc() {
vector_destroy(v);
}
-void test_vector_sort_int_desc() {
+void test_vector_sort_int_desc(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -183,7 +183,7 @@ vector_order_t cmp_string_desc(const void *x, const void *y) {
return VECTOR_ORDER_EQ;
}
-void test_vector_sort_string() {
+void test_vector_sort_string(void) {
vector_result_t res = vector_new(5, sizeof(char*));
assert(res.status == VECTOR_OK);
@@ -234,7 +234,7 @@ vector_order_t cmp_person_by_name(const void *x, const void *y) {
return VECTOR_ORDER_EQ;
}
-void test_vector_sort_struct_by_age() {
+void test_vector_sort_struct_by_age(void) {
vector_result_t res = vector_new(5, sizeof(Person));
assert(res.status == VECTOR_OK);
@@ -266,7 +266,7 @@ void test_vector_sort_struct_by_age() {
vector_destroy(people);
}
-void test_vector_sort_struct_by_name() {
+void test_vector_sort_struct_by_name(void) {
vector_result_t res = vector_new(5, sizeof(Person));
assert(res.status == VECTOR_OK);
@@ -305,7 +305,7 @@ void test_vector_sort_struct_by_name() {
}
// Set vector element
-void test_vector_set() {
+void test_vector_set(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -324,7 +324,7 @@ void test_vector_set() {
}
// Set vector element out of bounds
-void test_vector_set_ofb() {
+void test_vector_set_ofb(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -340,7 +340,7 @@ void test_vector_set_ofb() {
}
// Pop element from vector
-void test_vector_pop() {
+void test_vector_pop(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -361,7 +361,7 @@ void test_vector_pop() {
}
// Test pop element from empty vector
-void test_vector_pop_empty() {
+void test_vector_pop_empty(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -374,7 +374,7 @@ void test_vector_pop_empty() {
}
// Clear vector
-void test_vector_clear() {
+void test_vector_clear(void) {
vector_result_t res = vector_new(5, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -396,7 +396,7 @@ void test_vector_clear() {
}
// Multiple operations in sequence (push, set, pop and clear)
-void test_vector_sequence() {
+void test_vector_sequence(void) {
vector_result_t res = vector_new(2, sizeof(int));
assert(res.status == VECTOR_OK);
@@ -426,7 +426,7 @@ void test_vector_sequence() {
}
// Vector with chars
-void test_vector_char() {
+void test_vector_char(void) {
vector_result_t res = vector_new(5, sizeof(char));
assert(res.status == VECTOR_OK);
@@ -449,7 +449,7 @@ typedef struct {
int y;
} Point;
-void test_vector_struct() {
+void test_vector_struct(void) {
vector_result_t res = vector_new(5, sizeof(Point));
assert(res.status == VECTOR_OK);
diff --git a/usage.c b/usage.c
index f74cd6d..d1eb05e 100644
--- a/usage.c
+++ b/usage.c
@@ -22,9 +22,9 @@
#include "src/map.h"
#include "src/bigint.h"
-static int vector_usage();
-static int map_usage();
-static int bigint_usage();
+static int vector_usage(void);
+static int map_usage(void);
+static int bigint_usage(void);
static vector_order_t cmp_int_asc(const void *x, const void *y);
static vector_order_t cmp_int_desc(const void *x, const void *y);
@@ -62,7 +62,7 @@ vector_order_t cmp_int_desc(const void *x, const void *y) {
return cmp_int_asc(y, x);
}
-int vector_usage() {
+int vector_usage(void) {
// Create a vector of 3 integers
vector_result_t res = vector_new(3, sizeof(int));
if (res.status != VECTOR_OK) {
@@ -203,7 +203,7 @@ int vector_usage() {
return 0;
}
-int map_usage() {
+int map_usage(void) {
// Create a new map
map_result_t res = map_new();
if (res.status != MAP_OK) {
@@ -304,7 +304,7 @@ int map_usage() {
return 0;
}
-int bigint_usage() {
+int bigint_usage(void) {
// Create two big integers
bigint_result_t x_res = bigint_from_string("123456789");
if (x_res.status != BIGINT_OK) {
@@ -389,4 +389,4 @@ int bigint_usage() {
bigint_destroy(prod); bigint_destroy(quotient); bigint_destroy(remainder);
return 0;
-}
\ No newline at end of file
+}