Skip to content

Commit 8b63519

Browse files
committed
Add more tests for windows testing (II)
1 parent 2406cc0 commit 8b63519

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

tests/test_nd.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,83 @@ static int test_nd_unary_int32_negative_blocks(void) {
271271
return status;
272272
}
273273

274+
static int test_nd_unary_int32_to_float64_padding(void) {
275+
int status = 0;
276+
int err = 0;
277+
me_expr* expr = NULL;
278+
int64_t shape[1] = {10};
279+
int32_t chunkshape[1] = {3};
280+
int32_t blockshape[1] = {3};
281+
me_variable vars[] = {{"x", ME_INT32}};
282+
283+
int rc = me_compile_nd("arccos(x)", vars, 1, ME_FLOAT64, 1,
284+
shape, chunkshape, blockshape, &err, &expr);
285+
if (rc != ME_COMPILE_SUCCESS) {
286+
printf("FAILED me_compile_nd unary int32->float64: %d (err=%d)\n", rc, err);
287+
return 1;
288+
}
289+
290+
const double expected = acos(0.0);
291+
const int64_t nchunks = (shape[0] + chunkshape[0] - 1) / chunkshape[0];
292+
const void* ptrs[] = {NULL};
293+
int32_t in[3] = {0, 0, 0};
294+
double out[3] = {-1.0, -1.0, -1.0};
295+
296+
for (int64_t nchunk = 0; nchunk < nchunks; nchunk++) {
297+
int64_t valid = -1;
298+
rc = me_nd_valid_nitems(expr, nchunk, 0, &valid);
299+
if (rc != ME_EVAL_SUCCESS) {
300+
printf("FAILED me_nd_valid_nitems int32->float64 (rc=%d, chunk=%lld)\n",
301+
rc, (long long)nchunk);
302+
status = 1;
303+
goto cleanup;
304+
}
305+
306+
int64_t expected_valid = shape[0] - nchunk * chunkshape[0];
307+
if (expected_valid > blockshape[0]) expected_valid = blockshape[0];
308+
if (expected_valid < 0) expected_valid = 0;
309+
if (valid != expected_valid) {
310+
printf("FAILED valid count int32->float64 (chunk=%lld got=%lld exp=%lld)\n",
311+
(long long)nchunk, (long long)valid, (long long)expected_valid);
312+
status = 1;
313+
goto cleanup;
314+
}
315+
316+
for (int i = 0; i < 3; i++) {
317+
in[i] = (i < valid) ? 0 : 12345;
318+
out[i] = -1.0;
319+
}
320+
ptrs[0] = in;
321+
rc = me_eval_nd(expr, ptrs, 1, out, 3, nchunk, 0, NULL);
322+
if (rc != ME_EVAL_SUCCESS) {
323+
printf("FAILED me_eval_nd int32->float64 (rc=%d, chunk=%lld)\n",
324+
rc, (long long)nchunk);
325+
status = 1;
326+
goto cleanup;
327+
}
328+
for (int i = 0; i < valid; i++) {
329+
if (fabs(out[i] - expected) > 1e-12) {
330+
printf("FAILED int32->float64 mismatch chunk=%lld idx=%d got=%.15f exp=%.15f\n",
331+
(long long)nchunk, i, out[i], expected);
332+
status = 1;
333+
goto cleanup;
334+
}
335+
}
336+
for (int i = (int)valid; i < 3; i++) {
337+
if (out[i] != 0.0) {
338+
printf("FAILED int32->float64 padding chunk=%lld idx=%d got=%.15f exp=0.0\n",
339+
(long long)nchunk, i, out[i]);
340+
status = 1;
341+
goto cleanup;
342+
}
343+
}
344+
}
345+
346+
cleanup:
347+
me_free(expr);
348+
return status;
349+
}
350+
274351
static int test_3d_partial(void) {
275352
int status = 0;
276353
int err = 0;
@@ -919,6 +996,11 @@ int main(void) {
919996
failed |= t11;
920997
printf("Result: %s\n\n", t11 ? "FAIL" : "PASS");
921998

999+
printf("Test 12: Unary int32->float64 with padding\n");
1000+
int t12 = test_nd_unary_int32_to_float64_padding();
1001+
failed |= t12;
1002+
printf("Result: %s\n\n", t12 ? "FAIL" : "PASS");
1003+
9221004
printf("=====================\n");
9231005
printf("Summary: %s\n", failed ? "FAIL" : "PASS");
9241006
return failed ? 1 : 0;

0 commit comments

Comments
 (0)