summaryrefslogtreecommitdiffhomepage
path: root/misc/tests
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-31 12:53:46 +0100
committerTyge Løvset <[email protected]>2023-01-31 12:53:46 +0100
commit5bbcae2a3add163ea3b7a91d65fda6836c18f410 (patch)
tree304ab8ca8f632f56e53ee2bc568fb834da91b13c /misc/tests
parent209bf743e0c1253a4bc81d2ffb6897f657a84c8a (diff)
downloadSTC-modified-5bbcae2a3add163ea3b7a91d65fda6836c18f410.tar.gz
STC-modified-5bbcae2a3add163ea3b7a91d65fda6836c18f410.zip
Updates, and prepare for the big unsigned ==> signed transformation.
Diffstat (limited to 'misc/tests')
-rw-r--r--misc/tests/cspan_test.c53
-rw-r--r--misc/tests/ctest.h51
2 files changed, 68 insertions, 36 deletions
diff --git a/misc/tests/cspan_test.c b/misc/tests/cspan_test.c
index 32634795..3f03ef0f 100644
--- a/misc/tests/cspan_test.c
+++ b/misc/tests/cspan_test.c
@@ -72,3 +72,56 @@ CTEST(cspan, slice2) {
ASSERT_EQ(65112, sum);
}
}
+
+
+#define i_type Tiles
+#define i_val intspan3
+#include <stc/cstack.h>
+
+CTEST_FIXTURE(cspan_cube) {
+ cstack_int stack;
+ Tiles tiles;
+};
+
+CTEST_SETUP(cspan_cube) {
+ enum {TSIZE=4, CUBE=64, N=CUBE*CUBE*CUBE};
+
+ fix->stack = cstack_int_init();
+ fix->tiles = Tiles_init();
+
+ cstack_int_reserve(&fix->stack, N);
+ c_FORRANGE (i, N)
+ cstack_int_push(&fix->stack, i+1);
+
+ intspan3 ms3 = cspan_md(fix->stack.data, CUBE, CUBE, CUBE);
+
+ c_FORRANGE (i, 0, ms3.dim[0], TSIZE) {
+ c_FORRANGE (j, 0, ms3.dim[1], TSIZE) {
+ c_FORRANGE (k, 0, ms3.dim[2], TSIZE) {
+ intspan3 tile = ms3;
+ cspan_slice(&tile, {i, i + TSIZE}, {j, j + TSIZE}, {k, k + TSIZE});
+ Tiles_push(&fix->tiles, tile);
+ }
+ }
+ }
+}
+
+// Optional teardown function for suite, called after every test in suite
+CTEST_TEARDOWN(cspan_cube) {
+ cstack_int_drop(&fix->stack);
+ Tiles_drop(&fix->tiles);
+}
+
+
+CTEST_F(cspan_cube, slice3) {
+ intptr_t n = cstack_int_size(&fix->stack);
+ //printf("\ntiles: %zi, cells: %zi\n", Tiles_size(&fix->tiles), n);
+
+ int64_t sum = 0;
+ // iterate each 3d tile in sequence
+ c_FOREACH (i, Tiles, fix->tiles)
+ c_FOREACH (t, intspan3, *i.ref)
+ sum += *t.ref;
+
+ ASSERT_EQ(n*(n + 1)/2, sum);
+}
diff --git a/misc/tests/ctest.h b/misc/tests/ctest.h
index 294a6ca2..6cfb507a 100644
--- a/misc/tests/ctest.h
+++ b/misc/tests/ctest.h
@@ -113,14 +113,14 @@ struct ctest {
#ifdef __cplusplus
#define CTEST_SETUP(sname) \
- template <> void CTEST_IMPL_SETUP_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* self)
+ template <> void CTEST_IMPL_SETUP_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix)
#define CTEST_TEARDOWN(sname) \
- template <> void CTEST_IMPL_TEARDOWN_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* self)
+ template <> void CTEST_IMPL_TEARDOWN_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix)
#define CTEST_FIXTURE(sname) \
- template <typename T> void CTEST_IMPL_SETUP_FNAME(sname)(T* self) { } \
- template <typename T> void CTEST_IMPL_TEARDOWN_FNAME(sname)(T* self) { } \
+ template <typename T> void CTEST_IMPL_SETUP_FNAME(sname)(T* fix) { } \
+ template <typename T> void CTEST_IMPL_TEARDOWN_FNAME(sname)(T* fix) { } \
struct CTEST_IMPL_DATA_SNAME(sname)
#define CTEST_IMPL_CTEST(sname, tname, tskip) \
@@ -130,23 +130,23 @@ struct ctest {
#define CTEST_IMPL_CTEST_F(sname, tname, tskip) \
static struct CTEST_IMPL_DATA_SNAME(sname) CTEST_IMPL_DATA_TNAME(sname, tname); \
- static void CTEST_IMPL_FNAME(sname, tname)(struct CTEST_IMPL_DATA_SNAME(sname)* self); \
+ static void CTEST_IMPL_FNAME(sname, tname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix); \
static void (*CTEST_IMPL_SETUP_TPNAME(sname, tname))(struct CTEST_IMPL_DATA_SNAME(sname)*) = &CTEST_IMPL_SETUP_FNAME(sname)<struct CTEST_IMPL_DATA_SNAME(sname)>; \
static void (*CTEST_IMPL_TEARDOWN_TPNAME(sname, tname))(struct CTEST_IMPL_DATA_SNAME(sname)*) = &CTEST_IMPL_TEARDOWN_FNAME(sname)<struct CTEST_IMPL_DATA_SNAME(sname)>; \
CTEST_IMPL_STRUCT(sname, tname, tskip, &CTEST_IMPL_DATA_TNAME(sname, tname), &CTEST_IMPL_SETUP_TPNAME(sname, tname), &CTEST_IMPL_TEARDOWN_TPNAME(sname, tname)); \
- static void CTEST_IMPL_FNAME(sname, tname)(struct CTEST_IMPL_DATA_SNAME(sname)* self)
+ static void CTEST_IMPL_FNAME(sname, tname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix)
#else
#define CTEST_SETUP(sname) \
- static void CTEST_IMPL_SETUP_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* self); \
+ static void CTEST_IMPL_SETUP_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix); \
static void (*CTEST_IMPL_SETUP_FPNAME(sname))(struct CTEST_IMPL_DATA_SNAME(sname)*) = &CTEST_IMPL_SETUP_FNAME(sname); \
- static void CTEST_IMPL_SETUP_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* self)
+ static void CTEST_IMPL_SETUP_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix)
#define CTEST_TEARDOWN(sname) \
- static void CTEST_IMPL_TEARDOWN_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* self); \
+ static void CTEST_IMPL_TEARDOWN_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix); \
static void (*CTEST_IMPL_TEARDOWN_FPNAME(sname))(struct CTEST_IMPL_DATA_SNAME(sname)*) = &CTEST_IMPL_TEARDOWN_FNAME(sname); \
- static void CTEST_IMPL_TEARDOWN_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* self)
+ static void CTEST_IMPL_TEARDOWN_FNAME(sname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix)
#define CTEST_FIXTURE(sname) \
struct CTEST_IMPL_DATA_SNAME(sname); \
@@ -161,9 +161,9 @@ struct ctest {
#define CTEST_IMPL_CTEST_F(sname, tname, tskip) \
static struct CTEST_IMPL_DATA_SNAME(sname) CTEST_IMPL_DATA_TNAME(sname, tname); \
- static void CTEST_IMPL_FNAME(sname, tname)(struct CTEST_IMPL_DATA_SNAME(sname)* self); \
+ static void CTEST_IMPL_FNAME(sname, tname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix); \
CTEST_IMPL_STRUCT(sname, tname, tskip, &CTEST_IMPL_DATA_TNAME(sname, tname), &CTEST_IMPL_SETUP_FPNAME(sname), &CTEST_IMPL_TEARDOWN_FPNAME(sname)); \
- static void CTEST_IMPL_FNAME(sname, tname)(struct CTEST_IMPL_DATA_SNAME(sname)* self)
+ static void CTEST_IMPL_FNAME(sname, tname)(struct CTEST_IMPL_DATA_SNAME(sname)* fix)
#endif
@@ -186,12 +186,6 @@ void assert_wstr(const char* cmp, const wchar_t *exp, const wchar_t *real, const
#define ASSERT_WSTREQ(exp, real) assert_wstr("==", exp, real, __FILE__, __LINE__)
#define ASSERT_WSTRNE(exp, real) assert_wstr("!=", exp, real, __FILE__, __LINE__)
-void assert_data(const unsigned char* exp, size_t expsize,
- const unsigned char* real, size_t realsize,
- const char* caller, int line);
-#define ASSERT_DATA(exp, expsize, real, realsize) \
- assert_data(exp, expsize, real, realsize, __FILE__, __LINE__)
-
#define CTEST_FLT_EPSILON 1e-5
#define CTEST_DBL_EPSILON 1e-12
@@ -363,21 +357,6 @@ void assert_wstr(const char* cmp, const wchar_t *exp, const wchar_t *real, const
}
}
-void assert_data(const unsigned char* exp, size_t expsize,
- const unsigned char* real, size_t realsize,
- const char* caller, int line) {
- size_t i;
- if (expsize != realsize) {
- CTEST_ERR("%s:%d expected %" PRIuMAX " bytes, got %" PRIuMAX, caller, line, (uintmax_t) expsize, (uintmax_t) realsize);
- }
- for (i=0; i<expsize; i++) {
- if (exp[i] != real[i]) {
- CTEST_ERR("%s:%d expected 0x%02x at offset %" PRIuMAX " got 0x%02x",
- caller, line, exp[i], (uintmax_t) i, real[i]);
- }
- }
-}
-
static bool get_compare_result(const char* cmp, int c3, bool eq) {
if (cmp[0] == '<')
return c3 < 0 || ((cmp[1] == '=') & eq);
@@ -443,7 +422,7 @@ void assert_fail(const char* caller, int line) {
static int suite_all(struct ctest* t) {
- (void) t; // fix unused parameter warning
+ (void) t; // avoid unused parameter warning
return 1;
}
@@ -466,8 +445,8 @@ static void sighandler(int signum)
const char msg_nocolor[] = "[SIGSEGV: Segmentation fault]\n";
const char* msg = color_output ? msg_color : msg_nocolor;
- write(STDOUT_FILENO, msg, (unsigned int)strlen(msg));
-
+ intptr_t n = write(STDOUT_FILENO, msg, (unsigned int)strlen(msg));
+ (void)n;
/* "Unregister" the signal handler and send the signal back to the process
* so it can terminate as expected */
signal(signum, SIG_DFL);