From d0ad8e5fb1a68a560ab6f89dda240f1e8fac84d7 Mon Sep 17 00:00:00 2001 From: Raffaele Date: Thu, 13 Jan 2022 23:09:36 +0100 Subject: [PATCH] added test unit --- .gitignore | 3 +- lina.c | 34 ++++++++++++++------ lina.o | Bin 0 -> 2320 bytes test.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 lina.o diff --git a/.gitignore b/.gitignore index 34a93a7..58463d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .swp -test \ No newline at end of file +test +.vscode \ No newline at end of file diff --git a/lina.c b/lina.c index d4afa67..465e160 100644 --- a/lina.c +++ b/lina.c @@ -1,9 +1,8 @@ #include // NULL #include // assert +#include #include "lina.h" -// Evaluate the dot product C = A*B where C is of size m by l, A is m by n and B is n by l. -// NOTE: C can't be the same pointer of A or B. void lina_dot(double *A, double *B, double *C, int m, int n, int l){ assert(m > 0 && n > 0 && l > 0); @@ -32,8 +31,6 @@ void lina_dot(double *A, double *B, double *C, int m, int n, int l){ } -// Evaluate C = A + B where A,B,C are m by n. -// NOTE: C can be the same location of A or B. void lina_add(double *A, double *B, double *C, int m, int n){ assert(m > 0 && n > 0); @@ -46,8 +43,6 @@ void lina_add(double *A, double *B, double *C, int m, int n){ C[i * n + j] = A[i * n + j] + B[i * n + j]; } -// Evaluate B = k*A where A and B are m by n matrices. -// NOTE: B can be the same location of A. void lina_scale(double *A, double *B, double k, int m, int n){ assert(m > 0 && n > 0); @@ -60,13 +55,34 @@ void lina_scale(double *A, double *B, double k, int m, int n){ B[i * n + j] = k * A[i * n + j]; } -// Evaluate B = A^t (the transpose of A) where A is m by n. -// NOTE: B can be the same location of A. void lina_transpose(double *A, double *B, int m, int n){ assert(m > 0 && n > 0); assert(A != NULL && B != NULL); + double *support = malloc(sizeof(*support) * m * n); + + for(int i=0;i?ksBbLs&_s zC6J)-A?nq){sAA9jFli*%7=ZFAW~d#+YFXiuygO+t9Qof#S3@NIp25Az2|(hv(IqX z?J`M1d`ajQ+K)Jjkh^l<_fyx8YS1zCTR!tQs2V?1<4IOE5*gJ9t{Q=r4g)WB7=cAK zg;&)ZI4jTmfg%=VdU%M zB!ok7jMLtoY9?=FZ7vb#EkcPx1so|m`ep@Q7A4Ecd#LGA_zu1(?{395Z~ zY2uarwpHg-FjUu~B+f%&-iH_E*{(fhK#oKn?gvpzLRSw$? zy8?FSoggYhXo+Ah*ksk221$?ZA!*VrHPlp9&%p=O2sqhfHIWYrpKw1fYd>D;YLp;_ zayKc9&^KZ^U-p^Ml)umTcNYHj9{-r}r$zoQr5SV3kXFjkuib+TnaSzPCpb*)uv~j8 zSV&!cpwcrDfCIT1+13gJf@lgR?qMv8;xoSSQEqF zu+gZ7fT7U`5lsnE(>EB^O-CCXG@W=z8x5PT9@8T6@n}3us*s015mic5%WuPZfBiO` z_cv|Bd4EWWPmSr?09ZX{+7a&Q;Yl4SgPN`(Wgs3$N+>!u7LEWGiRxhmezq-fT?;*A z@o*%ejK`wm;g~*!lvsFFQ^F&CLosd49EEjoIMV=SL~8q+_Os(Yh~ltZMp1K?Vf_2z z+_tTb^UG=VEZk*I*yl z!|FXeky$dUxOyQVXWHxitbSfh2H#%a4H)@<^TQUGT46^03_Jps^vUZ_G2H2HLS@E0V8MF>j~y0m7Cq)2E4fJ`jP(ur}_m}KP(o5Z?FFcL931* literal 0 HcmV?d00001 diff --git a/test.c b/test.c index 673ad8d..67df82d 100644 --- a/test.c +++ b/test.c @@ -1,8 +1,96 @@ #include +#include +#include #include "lina.h" +#define NUM_TESTS 100 //Number of tests case to create +#define MATRIX_MAX_ROWS 4 //Max rows that a matrix can have +#define MATRIX_MAX_COLLUMNS 4 //Max collumns a matrix can have +#define MAX_VALUE 15 //Max value a matrix can have +//Matrix type. A is m by n + +typedef struct matrix_t +{ + double *A; + int m; + int n; +}matrix_t; + +//Dinamically create NUM_TESTS tests case randomly generating matrices with random values (whom max is MAX_VALUE) +//and random collumns and row numbers (whom max is MATRIX_MAX_ROWS and MATRIX_MAX_COLLUMNS) +void create_tests(matrix_t **tests); +//Free the heap memory from the test structure +void delete_tests(matrix_t **tests); + +//Print the matrix A with size m by n +void pmatrix(double *A, int m, int n); + int main() { - fprintf(stderr, "There's nothing here yet..\n"); + + + matrix_t *tests[NUM_TESTS]; + + create_tests(tests); + + pmatrix(tests[0]->A,tests[0]->m,tests[0]->n); + return 0; -} \ No newline at end of file +} + + +void pmatrix(double *A,int m,int n){ + + for(int i = 0; iA = ptr; + m_point->m = rows; + m_point->n = cols; + + tests[i] = m_point; + } + + +} + +void delete_tests(matrix_t **tests){ + + for(int i=0;iA); + free(tests[i]); + + } + + tests = NULL; + +}