./tests/s21_calc_complements_test.c:205:F:case_calc_complements:test_calc_complements_7:0: Assertion 'res == 0' failed: res == 2, 0 == 0
START_TEST(test_calc_complements_7) {
  int res = 0;
  matrix_t A = {0};
  matrix_t Z = {0};

  s21_create_matrix(1, 1, &A);
  A.matrix[0][0] = 21.0;

  res = s21_calc_complements(&A, &Z);

  ck_assert_int_eq(res, 0);
  s21_remove_matrix(&A);
  s21_remove_matrix(&Z);
}
END_TEST
int s21_calc_complements(matrix_t *A, matrix_t *result) {
    if (A == NULL || A->matrix == NULL || result == NULL) {
        return ERROR_INIT;
    }

    int status = OK;
    status = s21_create_matrix(A->rows, A->columns, result);

    if (status == OK) {
        for (int i = 0; i < A->rows && status == OK; ++i) {
            for (int j = 0; j < A->columns && status == OK; ++j) {
                matrix_t minor_matrix;
                status = s21_minor_matrix(A, i, j, &minor_matrix);
                if (status != OK) {
                    return ERROR_CALC;
                }
                double minor_det = 0.0;
                status = s21_determinant(&minor_matrix, &minor_det);
                if (status != OK) {
                    return ERROR_CALC;
                }
                result->matrix[i][j] = minor_det * pow(-1, i+j);
                s21_remove_matrix(&minor_matrix);
                if (!isfinite(result->matrix[i][j])) {
                    status = ERROR_CALC;
                }
            }
        }
    }

    return status;
}
int s21_minor_matrix(matrix_t *A, int rows, int columns, matrix_t *result) {
  if (A == NULL || A->matrix == NULL || result == NULL) {
        return ERROR_INIT;
  }

  int status = OK;
  status = s21_create_matrix(A->rows-1, A->columns-1, result);

  if (status == OK) {
       int new_row = 0;
    for (int i = 0; i < A->rows; ++i) {
        if (i == rows) {
            continue; 
        }

        int new_col = 0;
        for (int j = 0; j < A->columns; ++j) {
            if (j == columns) {
                continue; 
            }

            result->matrix[new_row][new_col] = A->matrix[i][j];
            new_col++;
        }
        new_row++;
    }
  }
  return status;
}
int s21_determinant(matrix_t *A, double *result) {
    if (A == NULL || A->matrix == NULL || result == NULL) {
        return ERROR_INIT;
    }

    if (A->columns != A->rows) {
        return ERROR_CALC;
    }

    int status = OK;
    if (A->rows == 1) {
        *result = A->matrix[0][0];
    }
    else if (A->rows == 2) {
        *result = A->matrix[0][0] * A->matrix[1][1] - A->matrix[0][1] * A->matrix[1][0];
    } else {
    double det = 0.0;
    for (int i = 0; i < A->rows; ++i) {
        matrix_t minor_matrix;
        int status = s21_minor_matrix(A, 0, i, &minor_matrix);
        if (status != OK) {
            return ERROR_CALC;
        }
        double minor_det;
        status = s21_determinant(&minor_matrix, &minor_det); 
        if (status != OK) {
            return ERROR_CALC;
        }
        if (i % 2 == 0) {
            det += A->matrix[0][i] * minor_det;
        } else {
            det -= A->matrix[0][i] * minor_det;
        }
        s21_remove_matrix(&minor_matrix); 
    }
    *result = det;
    }
    return status;
}