|
funkalicious 0.1
|
#include <math.h>#include <stdio.h>#include <stdlib.h>#include <CUnit/CUnit.h>#include "tests/cunit-local.h"#include <glib.h>#include <libdotcode/write_binary_data.h>#include <libdotcode/read_binary_data.h>#include "readwrite_dotcodefiles.h"
Include dependency graph for readwrite_dotcodefiles.c:Go to the source code of this file.
Functions | |
| int | are_equal_typed (enum dotcode_type t, void *store1, void *store2, long unsigned int i) |
| int | grid_is_consistent (const struct dotcode_grid *g) |
| int | grids_are_same (const struct dotcode_grid *g1, const struct dotcode_grid *g2) |
| struct dotcode_grid * | write_specified_10x10x10_float8_grid (double *values) |
| struct dotcode_grid * | write_valued_10x10x10_float8_grid (double value) |
| void | write_zero_10x10x10_float8_grid (void) |
| void | write_one_10x10x10_float8_grid (void) |
| void | write_mone_10x10x10_float8_grid (void) |
| void | write_random_10x10x10_float8_grid (void) |
| void | read_zero_10x10x10_float8_grid (void) |
| void | read_mone_10x10x10_float8_grid (void) |
| void | read_one_10x10x10_float8_grid (void) |
| void | read_random_10x10x10_float8_grid (void) |
| void | libdotcode_readwrite_suite_add_tests (CU_pSuite suite) |
Variables | |
| struct dotcode_grid * | grids [4] |
| const char * | temp_filename = "/tmp/test-file-for-readwrite-dotcodefiles.tmptest" |
| int are_equal_typed | ( | enum dotcode_type | t, |
| void * | store1, | ||
| void * | store2, | ||
| long unsigned int | i | ||
| ) |
Definition at line 39 of file readwrite_dotcodefiles.c.
References DOTCODE_FLOAT4, DOTCODE_FLOAT8, and DOTCODE_INT.
Referenced by grids_are_same().
{
switch(t) {
case DOTCODE_INT:
return ((int*)store1)[i] == ((int*)store2)[i];
case DOTCODE_FLOAT8:
return ((double*)store1)[i] == ((double*)store2)[i];
case DOTCODE_FLOAT4:
return ((float*)store1)[i] == ((float*)store2)[i];
default:
return 0;
}
}
Here is the caller graph for this function:| int grid_is_consistent | ( | const struct dotcode_grid * | g | ) |
Definition at line 52 of file readwrite_dotcodefiles.c.
References dotcode_grid::data, dotcode_grid::gridsites, dotcode_array::imax, dotcode_array::imin, dotcode_tensor::indices, dotcode_tensor::Nd, dotcode_array::t, and dotcode_tensor::t.
{
CU_ASSERT(g->data->Nd == 3);
if(!(g->data->Nd == 3)) return 0;
enum dotcode_type t = g->data->t;
for(int i=0; i<3; i++) {
CU_ASSERT(g->gridsites[i]->t == t);
if(!(g->gridsites[i]->t == t)) return 0;
CU_ASSERT(g->gridsites[i]->imin == g->data->indices[i*2]);
if(!(g->gridsites[i]->imin == g->data->indices[i*2])) return 0;
CU_ASSERT(g->gridsites[i]->imax == g->data->indices[i*2+1]);
if(!(g->gridsites[i]->imax == g->data->indices[i*2+1])) return 0;
}
return 1;
}
| int grids_are_same | ( | const struct dotcode_grid * | g1, |
| const struct dotcode_grid * | g2 | ||
| ) |
Definition at line 67 of file readwrite_dotcodefiles.c.
References are_equal_typed(), dotcode_tensor::data, dotcode_grid::data, dotcode_grid::gridsites, dotcode_array::imax, dotcode_array::imin, dotcode_tensor::indices, dotcode_tensor::metadata, dotcode_tensor::Nd, dotcode_grid::Ng, dotcode_array::storage, dotcode_tensor::t, and dotcode_array::t.
Referenced by read_mone_10x10x10_float8_grid(), read_one_10x10x10_float8_grid(), read_random_10x10x10_float8_grid(), and read_zero_10x10x10_float8_grid().
{
for(int i=0; i<3; i++) {
CU_ASSERT(g1->gridsites[i]->t == g2->gridsites[i]->t);
if(!(g1->gridsites[i]->t == g2->gridsites[i]->t)) return 0;
CU_ASSERT(g1->gridsites[i]->imin == g2->gridsites[i]->imin);
if(!(g1->gridsites[i]->imin == g2->gridsites[i]->imin)) return 0;
CU_ASSERT(g1->gridsites[i]->imax == g2->gridsites[i]->imax);
if(!(g1->gridsites[i]->imax == g2->gridsites[i]->imax)) return 0;
for(int j=0; j<(g1->gridsites[i]->imax - g1->gridsites[i]->imin); j++) {
CU_ASSERT(are_equal_typed(g1->gridsites[i]->t, g1->gridsites[i]->storage, g2->gridsites[i]->storage, j));
if(!are_equal_typed(g1->gridsites[i]->t, g1->gridsites[i]->storage, g2->gridsites[i]->storage, j)) return 0;
}
}
for(int i=0; i<3; i++) {
CU_ASSERT(g1->Ng[i] == g2->Ng[i]);
if(!(g1->Ng[i] == g2->Ng[i])) return 0;
}
CU_ASSERT(g1->data->t == g2->data->t);
if(!(g1->data->t == g2->data->t)) return 0;
CU_ASSERT(!(g_strcmp0(g1->data->metadata, g2->data->metadata)));
if(g_strcmp0(g1->data->metadata, g2->data->metadata)) return 0;
CU_ASSERT(g1->data->Nd == g2->data->Nd);
if(!(g1->data->Nd == g2->data->Nd)) return 0;
long int size = 1;
for(int i=0; i<(g1->data->Nd); i++) {
CU_ASSERT(g1->data->indices[2*i] == g2->data->indices[2*i]);
if(!(g1->data->indices[2*i] == g2->data->indices[2*i])) return 0;
CU_ASSERT(g1->data->indices[2*i+1] == g2->data->indices[2*i+1]);
if(!(g1->data->indices[2*i+1] == g2->data->indices[2*i+1])) return 0;
size *= (g1->data->indices[2*i+1] == g1->data->indices[2*i]);
}
for(long int i=0; i<size; i++) {
CU_ASSERT(are_equal_typed(g1->data->t, g1->data->data, g2->data->data, i));
if(!(are_equal_typed(g1->data->t, g1->data->data, g2->data->data, i))) return 0;
}
return 1;
}
Here is the call graph for this function:
Here is the caller graph for this function:| void libdotcode_readwrite_suite_add_tests | ( | CU_pSuite | suite | ) |
Definition at line 268 of file readwrite_dotcodefiles.c.
References dotcode_free_type(), DOTCODE_GRID, e, read_mone_10x10x10_float8_grid(), read_one_10x10x10_float8_grid(), read_random_10x10x10_float8_grid(), read_zero_10x10x10_float8_grid(), write_mone_10x10x10_float8_grid(), write_one_10x10x10_float8_grid(), write_random_10x10x10_float8_grid(), and write_zero_10x10x10_float8_grid().
Referenced by main().
{
CU_add_test(suite, "Writing zero 10x10x10 Float8 Grid", write_zero_10x10x10_float8_grid);
CU_add_test(suite, "Reading back zero 10x10x10 Float8 Grid", read_zero_10x10x10_float8_grid);
CU_add_test(suite, "Writing one 10x10x10 Float8 Grid", write_one_10x10x10_float8_grid);
CU_add_test(suite, "Reading one zero 10x10x10 Float8 Grid", read_one_10x10x10_float8_grid);
CU_add_test(suite, "Writing -one 10x10x10 Float8 Grid", write_mone_10x10x10_float8_grid);
CU_add_test(suite, "Reading -one zero 10x10x10 Float8 Grid", read_mone_10x10x10_float8_grid);
CU_add_test(suite, "Writing random 10x10x10 Float8 Grid", write_random_10x10x10_float8_grid);
CU_add_test(suite, "Reading back random 10x10x10 Float8 Grid", read_random_10x10x10_float8_grid);
GError *e = NULL;
/*Free the structures*/
for(int i=0; i<4; i++) {
if(grids[i] == NULL) {
fprintf(stderr, "ERROR: grids[%d] is NULL!\n", i);
continue;
}
dotcode_free_type(DOTCODE_GRID, grids[i], 1, &e, TRUE);
if(e != NULL) {
fprintf(stderr, "ERROR freeing %dth grid: %s\n", i, e->message);
g_error_free(e);
}
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| void read_mone_10x10x10_float8_grid | ( | void | ) |
Definition at line 199 of file readwrite_dotcodefiles.c.
References DOTCODE_GRID, e, grids_are_same(), read_dotcode_generic_file(), and temp_filename.
Referenced by libdotcode_readwrite_suite_add_tests().
{
enum dotcode_type t;
GFile *f = g_file_new_for_path(temp_filename);
GError *e = NULL;
struct dotcode_grid *g = read_dotcode_generic_file(&t, f, &e);
if(e != NULL) {
fprintf(stderr, "ERROR reading grid from file (%s): %s", temp_filename, e->message);
g_error_free(e);
CU_FAIL("Fail!");
return;
}
CU_ASSERT(e == NULL);
CU_ASSERT(t == DOTCODE_GRID);
if(t != DOTCODE_GRID) return;
int same = grids_are_same(g, grids[2]);
CU_ASSERT(same != 0);
if(e != NULL) {
fprintf(stderr, "ERROR freeing 1 grid: %s\n", e->message);
g_error_free(e);
CU_FAIL("Failed to free 1 grid.\n");
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| void read_one_10x10x10_float8_grid | ( | void | ) |
Definition at line 221 of file readwrite_dotcodefiles.c.
References DOTCODE_GRID, e, grids_are_same(), read_dotcode_generic_file(), and temp_filename.
Referenced by libdotcode_readwrite_suite_add_tests().
{
enum dotcode_type t;
GFile *f = g_file_new_for_path(temp_filename);
GError *e = NULL;
struct dotcode_grid *g = read_dotcode_generic_file(&t, f, &e);
if(e != NULL) {
fprintf(stderr, "ERROR reading grid from file (%s): %s", temp_filename, e->message);
g_error_free(e);
CU_FAIL("Fail!");
return;
}
CU_ASSERT(e == NULL);
CU_ASSERT(t == DOTCODE_GRID);
if(t != DOTCODE_GRID) return;
int same = grids_are_same(g, grids[1]);
CU_ASSERT(same != 0);
if(e != NULL) {
fprintf(stderr, "ERROR freeing -1 grid: %s\n", e->message);
g_error_free(e);
CU_FAIL("Failed to free -1 grid.\n");
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| void read_random_10x10x10_float8_grid | ( | void | ) |
Definition at line 243 of file readwrite_dotcodefiles.c.
References dotcode_free_type(), DOTCODE_GRID, e, grids_are_same(), read_dotcode_generic_file(), and temp_filename.
Referenced by libdotcode_readwrite_suite_add_tests().
{
enum dotcode_type t;
GFile *f = g_file_new_for_path(temp_filename);
GError *e = NULL;
struct dotcode_grid *g = read_dotcode_generic_file(&t, f, &e);
if(e != NULL) {
fprintf(stderr, "ERROR reading grid from file (%s): %s", temp_filename, e->message);
g_error_free(e);
CU_FAIL("Fail!");
return;
}
CU_ASSERT(e == NULL);
CU_ASSERT(t == DOTCODE_GRID);
if(t != DOTCODE_GRID) return;
int same = grids_are_same(g, grids[3]);
CU_ASSERT(same != 0);
dotcode_free_type(DOTCODE_GRID, g, 1, &e, TRUE);
if(e != NULL) {
fprintf(stderr, "ERROR freeing random grid: %s\n", e->message);
g_error_free(e);
CU_FAIL("Failed to free random grid.\n");
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| void read_zero_10x10x10_float8_grid | ( | void | ) |
Definition at line 176 of file readwrite_dotcodefiles.c.
References DOTCODE_GRID, e, grids_are_same(), read_dotcode_generic_file(), and temp_filename.
Referenced by libdotcode_readwrite_suite_add_tests().
{
enum dotcode_type t;
GFile *f = g_file_new_for_path(temp_filename);
GError *e = NULL;
struct dotcode_grid *g = read_dotcode_generic_file(&t, f, &e);
if(e != NULL) {
fprintf(stderr, "ERROR reading grid from file (%s): %s", temp_filename, e->message);
g_error_free(e);
CU_FAIL("Fail!");
return;
}
CU_ASSERT(e == NULL);
CU_ASSERT(t == DOTCODE_GRID);
if(t != DOTCODE_GRID) return;
int same = grids_are_same(g, grids[0]);
CU_ASSERT(same != 0);
if(e != NULL) {
fprintf(stderr, "ERROR freeing zero grid: %s\n", e->message);
g_error_free(e);
CU_FAIL("Failed to free zero grid.\n");
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| void write_mone_10x10x10_float8_grid | ( | void | ) |
Definition at line 162 of file readwrite_dotcodefiles.c.
References write_valued_10x10x10_float8_grid().
Referenced by libdotcode_readwrite_suite_add_tests().
{
grids[2] = write_valued_10x10x10_float8_grid(-1.0);
//fprintf(stderr, "Allocated grids[2]=%p", (void*)grids[2]);
}
Here is the call graph for this function:
Here is the caller graph for this function:| void write_one_10x10x10_float8_grid | ( | void | ) |
Definition at line 158 of file readwrite_dotcodefiles.c.
References write_valued_10x10x10_float8_grid().
Referenced by libdotcode_readwrite_suite_add_tests().
{
grids[1] = write_valued_10x10x10_float8_grid(1.0);
//fprintf(stderr, "Allocated grids[1]=%p", (void*)grids[1]);
}
Here is the call graph for this function:
Here is the caller graph for this function:| void write_random_10x10x10_float8_grid | ( | void | ) |
Definition at line 167 of file readwrite_dotcodefiles.c.
References write_specified_10x10x10_float8_grid().
Referenced by libdotcode_readwrite_suite_add_tests().
{
srand48(time(NULL));
double* value = (double*)malloc(10*10*10*sizeof(double));
CU_ASSERT(value != NULL);
for(int i=0; i<(10*10*10); i++) value[i]=drand48();
grids[3] = write_specified_10x10x10_float8_grid(value);
//fprintf(stderr, "Allocated grids[3]=%p", (void*)grids[3]);
}
Here is the call graph for this function:
Here is the caller graph for this function:| struct dotcode_grid* write_specified_10x10x10_float8_grid | ( | double * | values | ) | [read] |
Definition at line 109 of file readwrite_dotcodefiles.c.
References dotcode_tensor::data, dotcode_grid::data, DOTCODE_FLOAT8, DOTCODE_GRID, dotcode_write_typed_file(), e, dotcode_grid::gridsites, dotcode_array::imax, dotcode_array::imin, dotcode_tensor::indices, dotcode_tensor::metadata, dotcode_tensor::Nd, dotcode_grid::Ng, dotcode_array::storage, dotcode_tensor::t, dotcode_array::t, and temp_filename.
Referenced by write_random_10x10x10_float8_grid(), and write_valued_10x10x10_float8_grid().
{
struct dotcode_grid *g = (struct dotcode_grid*)malloc(sizeof(struct dotcode_grid));
CU_ASSERT(g != NULL);
g->data = (struct dotcode_tensor*)malloc(sizeof(struct dotcode_tensor));
CU_ASSERT(g->data != NULL);
g->data->indices = (int*)malloc(6*sizeof(int));
CU_ASSERT(g->data->indices != NULL);
g->Ng[0]=g->Ng[1]=g->Ng[2] = 10;
g->data->Nd = 3;
long unsigned int size=1;
for(int i=0; i<3; i++) {
g->gridsites[i] = (struct dotcode_array*)malloc(sizeof(struct dotcode_array));
CU_ASSERT(g->gridsites[i] != NULL);
g->gridsites[i]->t = DOTCODE_FLOAT8;
g->data->indices[2*i] = g->gridsites[i]->imin = 0;
g->data->indices[2*i+1] = g->gridsites[i]->imax = 9;
g->gridsites[i]->storage = (double*)malloc(sizeof(double)*(g->gridsites[i]->imax-g->gridsites[i]->imin+1));
CU_ASSERT(g->gridsites[i]->storage != NULL);
for(int j=0; j<(g->gridsites[i]->imax-g->gridsites[i]->imin+1); j++) ((double*)g->gridsites[i]->storage)[j] = 0.5*((double)j);
size*=(g->gridsites[i]->imax-g->gridsites[i]->imin+1);
}
g->data->t = DOTCODE_FLOAT8;
g->data->metadata = "2.0";
g->data->data = values;
for(int i=0; i<size; i++) ((double*)g->data->data)[i] = values[i];
GError *e = NULL;
GFile *f = g_file_new_for_path(temp_filename);
e = dotcode_write_typed_file(DOTCODE_GRID, g, f);
if(e != NULL) {
fprintf(stderr, "ERROR writing grid to file (%s): %s", temp_filename, e->message);
g_error_free(e);
}
CU_ASSERT(e == NULL);
return g;
}
Here is the call graph for this function:
Here is the caller graph for this function:| struct dotcode_grid* write_valued_10x10x10_float8_grid | ( | double | value | ) | [read] |
Definition at line 145 of file readwrite_dotcodefiles.c.
References write_specified_10x10x10_float8_grid().
Referenced by write_mone_10x10x10_float8_grid(), write_one_10x10x10_float8_grid(), and write_zero_10x10x10_float8_grid().
{
double* val = (double*)malloc(10*10*10*sizeof(double));
CU_ASSERT(val != NULL);
for(int i=0; i<(10*10*10); i++) val[i]=value;
struct dotcode_grid *g= write_specified_10x10x10_float8_grid(val);
free(val);
return g;
}
Here is the call graph for this function:
Here is the caller graph for this function:| void write_zero_10x10x10_float8_grid | ( | void | ) |
Definition at line 154 of file readwrite_dotcodefiles.c.
References write_valued_10x10x10_float8_grid().
Referenced by libdotcode_readwrite_suite_add_tests().
{
grids[0] = write_valued_10x10x10_float8_grid(0.0);
//fprintf(stderr, "Allocated grids[0]=%p", (void*)grids[0]);
}
Here is the call graph for this function:
Here is the caller graph for this function:| struct dotcode_grid* grids[4] |
Definition at line 36 of file readwrite_dotcodefiles.c.
| const char* temp_filename = "/tmp/test-file-for-readwrite-dotcodefiles.tmptest" |
Definition at line 37 of file readwrite_dotcodefiles.c.
Referenced by read_mone_10x10x10_float8_grid(), read_one_10x10x10_float8_grid(), read_random_10x10x10_float8_grid(), read_zero_10x10x10_float8_grid(), and write_specified_10x10x10_float8_grid().