Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
Kate-Tol3 committed Apr 22, 2024
1 parent 6bb7aa6 commit a6da8ee
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 32 deletions.
Binary file modified a.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void read_complex_array(const size_t v,const size_t h, void* elems){
}
}

void complex_print(void* el){
Complex* elc = el;
void complex_print(const void* el){
const Complex* elc = el;
if ((elc->img) > 0){
printf("%.3lf + %.3lfi", elc->re, elc->img);
}
Expand Down
9 changes: 4 additions & 5 deletions field_info.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#pragma once
#include <stddef.h>

typedef void (*sum_el)(const void* v1,const void* v2, void* res);
typedef void (*mult_el)(const void* v1,const void* v2, void* res);
typedef void (*print_el)(void* el);
typedef void (*binary_op)(const void* v1,const void* v2, void* res);
typedef void (*print_el)(const void* el);
typedef void (*read_array)(const size_t v,const size_t h, void* elems);
typedef void (*set_zero)(void* ptr);
typedef void (*get_number)(void* ptr);

typedef struct {
const char* type;
size_t el_size;
sum_el sum_el;
mult_el mult_el;
binary_op sum_el;
binary_op mult_el;
print_el print_el;
read_array read_array;
set_zero set_zero;
Expand Down
6 changes: 2 additions & 4 deletions int.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ void read_int_array(const size_t v,const size_t h, void* elems){
}
}

void int_print(void* el){
printf("%7d", *((int*) el));
void int_print(const void* el){
printf("%7d", *((const int*) el));
}

//static void* INT_ZERO = NULL;

void int_set_zero(void* ptr){
*(int*)ptr = 0;
}
Expand Down
3 changes: 3 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,7 @@ int main(){
test_mult_matrix();
test_mult_on_number_matrix();
test_transpose_matrix();

menu();

}
1 change: 1 addition & 0 deletions matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string.h>
#include <stdlib.h>


//elemet setter and getter
void get_element(const Matrix* mat,const size_t i,const size_t j, void* val){
if ((mat->size_v >= i) && (mat->size_h >= j)){
Expand Down
4 changes: 2 additions & 2 deletions real.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void real_mult(const void* v1,const void* v2, void* res){
}


void real_print(void* el){
printf("%.3lf", *((double*) el));
void real_print(const void* el){
printf("%.3lf", *((const double*) el));
}

void read_real_array(const size_t v,const size_t h, void* elems){
Expand Down
38 changes: 19 additions & 19 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void test_int_sum() {
int_sum((const void*) v1_ptr, (const void*) v2_ptr, result);

assert(*(int*)result == expected_result);
printf("The function \"int_sum\" passed the test\n");
//printf("The function \"int_sum\" passed the test\n");
free(result);
}

Expand All @@ -40,7 +40,7 @@ void test_int_mult() {
int_mult((const void*) v1_ptr, (const void*) v2_ptr, result);

assert(*(int*)result == expected_result);
printf("The function \"mult_sum\" passed the test\n");
//printf("The function \"mult_sum\" passed the test\n");
free(result);
}

Expand All @@ -58,7 +58,7 @@ void test_real_sum() {

dval = *(double*)result - expected_result;
assert(dval < FLT_EPSILON);
printf("The function \"real_sum\" passed the test\n");
// printf("The function \"real_sum\" passed the test\n");
free(result);
}

Expand All @@ -75,7 +75,7 @@ void test_real_mult() {
real_mult((const void*) v1_ptr, (const void*) v2_ptr, result);
dval = *(double*)result - expected_result;
assert(dval < FLT_EPSILON);
printf("The function \"real_mult\" passed the test\n");
// printf("The function \"real_mult\" passed the test\n");
free(result);
}

Expand All @@ -91,7 +91,7 @@ void test_complex_sum() {
complex_sum((const void*) v1_ptr, (const void*) v2_ptr, result);

assert(((Complex*)result)->re == expected_result.re && ((Complex*)result)->img == expected_result.img);
printf("The function \"complex_sum\" passed the test\n");
//printf("The function \"complex_sum\" passed the test\n");
free(result);
}

Expand All @@ -106,7 +106,7 @@ void test_complex_mult() {

complex_mult((const void*) v1_ptr, (const void*) v2_ptr, result);
assert(((Complex*)result)->re == expected_result.re && ((Complex*)result)->img == expected_result.img);
printf("The function \"complex_mult\" passed the test\n");
// printf("The function \"complex_mult\" passed the test\n");
free(result);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ void test_sum_matrix_int(){
}
free(val);

printf("The function \"sum_matrix_int\" passed the test\n");
// printf("The function \"sum_matrix_int\" passed the test\n");
free(mat1);
free(mat2);
free(result);
Expand Down Expand Up @@ -178,7 +178,7 @@ void test_sum_matrix_real(){
}
free(val);

printf("The function \"sum_matrix_real\" passed the test\n");
// printf("The function \"sum_matrix_real\" passed the test\n");
free(mat1);
free(mat2);
free(result);
Expand Down Expand Up @@ -214,7 +214,7 @@ void test_sum_matrix_complex(){
}
free(val);

printf("The function \"sum_matrix_complex\" passed the test\n");
// printf("The function \"sum_matrix_complex\" passed the test\n");
free(mat1);
free(mat2);
free(result);
Expand Down Expand Up @@ -243,7 +243,7 @@ void test_mult_matrix_int(){
}
free(val);

printf("The function \"mult_matrix_int\" passed the test\n");
// printf("The function \"mult_matrix_int\" passed the test\n");
free(mat1);
free(mat2);
free(result);
Expand Down Expand Up @@ -275,14 +275,14 @@ void test_mult_matrix_real(){
}
free(val);

printf("The function \"mult_matrix_real\" passed the test\n");
// printf("The function \"mult_matrix_real\" passed the test\n");
free(mat1);
free(mat2);
free(result);
}

void test_mult_matrix_complex(){
//int
//complex
FieldInfo* info = get_info_int();
Matrix* mat1 = new_matrix(2, 2, info);
Matrix* mat2 = new_matrix(2, 2, info);
Expand All @@ -303,7 +303,7 @@ void test_mult_matrix_complex(){
}
free(val);

printf("The function \"mult_matrix_complex\" passed the test\n");
// printf("The function \"mult_matrix_complex\" passed the test\n");
free(mat1);
free(mat2);
free(result);
Expand All @@ -330,7 +330,7 @@ void test_mult_on_number_matrix_int(){
}
free(val);

printf("The function \"mult_on_number_matrix_int\" passed the test\n");
// printf("The function \"mult_on_number_matrix_int\" passed the test\n");
free(result);
}

Expand All @@ -356,7 +356,7 @@ void test_mult_on_number_matrix_real(){
}
free(val);

printf("The function \"mult_on_number_matrix_real\" passed the test\n");
//printf("The function \"mult_on_number_matrix_real\" passed the test\n");
free(result);
}

Expand Down Expand Up @@ -386,7 +386,7 @@ void test_mult_on_number_matrix_complex(){
}
free(val);

printf("The function \"mult_on_number_matrix_complex\" passed the test\n");
// printf("The function \"mult_on_number_matrix_complex\" passed the test\n");
free(result);
}

Expand All @@ -411,7 +411,7 @@ void test_transpose_matrix_int(){
}
free(val);

printf("The function \"transpose_matrix_int\" passed the test\n");
// printf("The function \"transpose_matrix_int\" passed the test\n");
free(matrix);
free(result);
}
Expand All @@ -438,7 +438,7 @@ void test_transpose_matrix_real(){
}
free(val);

printf("The function \"transpose_matrix_real\" passed the test\n");
// printf("The function \"transpose_matrix_real\" passed the test\n");
free(matrix);
free(result);
}
Expand Down Expand Up @@ -471,7 +471,7 @@ void test_transpose_matrix_complex(){
}
free(val);

printf("The function \"transpose_matrix_complex\" passed the test\n");
// printf("The function \"transpose_matrix_complex\" passed the test\n");
free(matrix);
free(result);
}
Expand Down

0 comments on commit a6da8ee

Please sign in to comment.