diff options
author | Mitya Selivanov <0x7fffff@guattari.ru> | 2022-08-06 16:32:59 +0400 |
---|---|---|
committer | Mitya Selivanov <0x7fffff@guattari.ru> | 2022-08-06 16:32:59 +0400 |
commit | f2fb8311d373cfd498dfbebc539982b8ad174615 (patch) | |
tree | 21cbc87cc5fb9ca3e75582ff2920aa83213617e4 /source/test/unittests/array_ref.test.c | |
parent | 1bf74ae58678cd91b95ccda6087be7ca0a452eee (diff) | |
download | kit-f2fb8311d373cfd498dfbebc539982b8ad174615.zip |
input buffer, dynamic array
Diffstat (limited to 'source/test/unittests/array_ref.test.c')
-rw-r--r-- | source/test/unittests/array_ref.test.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source/test/unittests/array_ref.test.c b/source/test/unittests/array_ref.test.c new file mode 100644 index 0000000..d8cbcec --- /dev/null +++ b/source/test/unittests/array_ref.test.c @@ -0,0 +1,42 @@ +#include "../../kit/array_ref.h" + +#define KIT_TEST_FILE array_ref +#include "../../kit_test/test.h" + +TEST("array ref equal") { + int foo[] = { 1, 2, 3, 4, 5, 6, 7 }; + int bar[] = { 3, 4, 5 }; + + AR(foo_ref, int) = { .size = 3, .values = foo + 2 }; + AR(bar_ref, int) = { .size = 3, .values = bar }; + + REQUIRE(AR_EQUAL(foo_ref, bar_ref)); +} + +static int compare(int const *left, int const *right) { + return *left - *right; +} + +TEST("array ref compare") { + int foo[] = { 1, 2, 3, 5 }; + int bar[] = { 1, 2, 4, 5 }; + + AR(foo_ref, int) = { .size = 3, .values = foo }; + AR(bar_ref, int) = { .size = 3, .values = bar }; + + REQUIRE(AR_COMPARE(foo_ref, bar_ref, compare) < 0); + REQUIRE(AR_COMPARE(bar_ref, foo_ref, compare) > 0); + REQUIRE(AR_COMPARE(foo_ref, foo_ref, compare) == 0); +} + +TEST("array ref different element sizes") { + int foo[] = { 1, 2, 3 }; + char bar[] = { 1, 2, 3 }; + + AR(foo_ref, int) = { .size = 3, .values = foo }; + AR(bar_ref, char) = { .size = 3, .values = bar }; + + REQUIRE(!AR_EQUAL(foo_ref, bar_ref)); + REQUIRE(AR_COMPARE(foo_ref, bar_ref, compare) > 0); + REQUIRE(AR_COMPARE(bar_ref, foo_ref, compare) < 0); +} |