Directory: | ./ |
---|---|
File: | s21_sub_matrix.c |
Date: | 2025-08-15 23:01:21 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 14 | 14 | 100.0% |
Branches: | 14 | 14 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "s21_matrix.h" | ||
2 | |||
3 | void s21_process_sub_matrix(matrix_t *A, matrix_t *B, matrix_t *result); | ||
4 | |||
5 | 12 | int s21_sub_matrix(matrix_t *A, matrix_t *B, matrix_t *result) { | |
6 |
6/6✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 6 times.
|
12 | if (s21_check_matrix_is_invalid(A) || s21_check_matrix_is_invalid(B) || |
7 | result == NULL) { | ||
8 | 6 | return ERROR; | |
9 | } | ||
10 | |||
11 | 6 | int code = OK; | |
12 |
4/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
|
6 | if (A->rows == B->rows && A->columns == B->columns) { |
13 | 2 | s21_create_matrix(A->rows, A->columns, result); | |
14 | |||
15 | 2 | s21_process_sub_matrix(A, B, result); | |
16 | } else { | ||
17 | 4 | code = CALC_ERROR; | |
18 | } | ||
19 | |||
20 | 6 | return code; | |
21 | } | ||
22 | |||
23 | 2 | void s21_process_sub_matrix(matrix_t *A, matrix_t *B, matrix_t *result) { | |
24 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
|
8 | for (int i = 0; i < A->rows; i++) { |
25 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
|
18 | for (int j = 0; j < A->columns; j++) { |
26 | 12 | result->matrix[i][j] = A->matrix[i][j] - B->matrix[i][j]; | |
27 | } | ||
28 | } | ||
29 | 2 | } | |
30 |