mirror of
https://github.com/bkthomps/Containers.git
synced 2025-11-16 12:34:47 +00:00
Increase code coverage so that other than the out-of-memory conditions, the code is entirely covered. Some areas of the code have been tweaked for performance optimizations. Bug fix! A bug has been identified and fixed in the unordered_multiset data structure in the unordered_multiset_remove_all function. This bug would occur when more than one entry exists in the bucket in which the element is occupying, and that element had a count of more than one.
42 lines
1.0 KiB
C
42 lines
1.0 KiB
C
#include "test.h"
|
|
#include "../src/array.h"
|
|
|
|
void test_array(void)
|
|
{
|
|
assert(!array_init(-1, sizeof(int)));
|
|
assert(!array_init(1, 0));
|
|
array me = array_init(10, sizeof(int));
|
|
assert(me);
|
|
assert(array_size(me) == 10);
|
|
for (int i = 0; i < 10; i++) {
|
|
int get = 0xdeadbeef;
|
|
array_get(&get, me, i);
|
|
assert(get == 0);
|
|
}
|
|
for (int i = 0; i < 10; i++) {
|
|
int get = 0xdeadbeef;
|
|
array_set(me, i, &i);
|
|
array_get(&get, me, i);
|
|
assert(get == i);
|
|
}
|
|
for (int i = 0; i < 10; i++) {
|
|
int get = 0xdeadbeef;
|
|
array_get(&get, me, i);
|
|
assert(get == i);
|
|
}
|
|
int arr[10] = {0};
|
|
array_copy_to_array(arr, me);
|
|
for (int i = 0; i < 10; i++) {
|
|
assert(arr[i] == i);
|
|
}
|
|
int *const data = array_get_data(me);
|
|
for (int i = 0; i < 10; i++) {
|
|
assert(data[i] == i);
|
|
}
|
|
int get = 0xdeadbeef;
|
|
assert(array_set(me, -1, &get) == -EINVAL);
|
|
assert(array_get(&get, me, -1) == -EINVAL);
|
|
me = array_destroy(me);
|
|
assert(!me);
|
|
}
|