Commit 4f82045a authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Add test while saving and loading blc_array

parent 82810dce
doc @ 3445be5d
Subproject commit 901d580d4ad8613f0703611ab9869a21297aac4e
Subproject commit 3445be5de05aea74c147e50557996160e5172ec5
FL32 NDEF 3x5
 ≥и@00000000 ≥и@00000000 ≥и@33B0000 ≥и@00000000 ≥и@00000000
\ No newline at end of file
6.300000 0.000000 0.000000
6.300000 0.000000 0.000000
6.300000 33.299999 0.000000
6.300000 0.000000 0.000000
6.300000 0.000000 0.000000
#include "blc_core.h"
int main(int argc, char **argv){
blc_array vector, matrix;
blc_array vector, matrix, matrix_copy;
int i, width, height;
//We define the properties of an array of type char (INT8) with undef format (i.e. the user use it as he wants), of one dimension (vector) of 32 values.
vector.def_array('INT8', 'NDEF', 1, 32);
//The properties .dims have to be freed.
//The property .dims have to be freed.
//Be careful the .data memory is not allocated ! This is usefull if you want to associate the data to your own memory.
//We display the properties
vector.fprint_properties(stderr);
fprintf(stderr, "\n");
//We allocate the memory
vector.allocate();
......@@ -19,9 +20,11 @@ int main(int argc, char **argv){
for(i=0; i!=vector.size; i++) vector.chars[i]=3;
//We define a matrix of 3x5
//The matrix is not allocated
matrix.def_array('FL32', 'NDEF', 2, 3, 5);
//We allocate the content
matrix.allocate();
//We display the dim sizes
matrix.fprint_dims(stderr);
fprintf(stderr, "\n");
......@@ -31,12 +34,30 @@ int main(int argc, char **argv){
height=matrix.dims[1].length;
fprintf(stderr, "width:%d, height:%d\n", width, height);
//We set the data to zero everywhere
memset(matrix.data, '0', matrix.size);
//We set the first column of the matrix to 6.3
for(i=0; i!=height; i++) matrix.floats[i*width]=6.3;
//Write 33.3 in the center
matrix.floats[1+width*2]=33.3;
matrix.fprint_tsv(stderr);
//We save the value as a blc file that we will be able to reread
matrix.save_blc_file("blc_core/t_array/array.blc");
matrix.save_tsv_file("blc_core/t_array/array.tsv"); //Bigger but readable in text mode or within spreadshit
//We reload the matrix which should be identical
matrix_copy.init_with_blc_file("blc_core/t_array/array.blc");
//we compare the content of the two matrixes
if (memcmp(matrix.data, matrix_copy.data, matrix.size)!=0) EXIT_ON_ARRAY_ERROR(&matrix,"The content of the saved and reloaded matrix are not the same");
/*Free the memory (.dims and .data)*/
vector.destroy();
matrix.destroy();
matrix_copy.destroy();
return 0;
}
\ No newline at end of file
#test
./compile.sh blc_core/t_array || { echo "Fail compiling blc_image/t_array"; exit 1; }
bin/t_array || { echo "Fail executing bin/t_array"; exit 2; }
set -o posix
#Need a comparaison of the output
echo "=== Testing blc_core ==="
./compile.sh blc_core/t_array &> /tmp/blc_core_test.log|| { echo "Fail compiling blc_image/t_array"; exit 1; }
bin/t_array >> /tmp/blc_core_test.log 2>&1 || { echo "Fail executing bin/t_array"; exit 2; }
( cd blc_core && git diff --exit-code t_array/array.tsv >> /tmp/blc_core_test.log 2>&1) || { echo "ERROR: The result of t_array/array.tsv is not the one expected"; exit 3; }
( cd blc_core && git diff --exit-code t_array/array.blc >> /tmp/blc_core_test.log 2>&1) || { echo "ERROR: The result of t_array/array.blc is not the one expected"; exit 3; }
echo "SUCCESS: blc_core has bin succesfully compiled, executed and tested"
echo "t_array succesfuly compiled, executed with the right output. (log in /tmp/blc_core_test.log)"
#Need a comparaison of the output
exit 0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment