| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "karpich_i_integrals_multistep_rectangle/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | |||
| 5 | #include "karpich_i_integrals_multistep_rectangle/common/include/common.hpp" | ||
| 6 | #include "task/include/task.hpp" | ||
| 7 | |||
| 8 | namespace karpich_i_integrals_multistep_rectangle { | ||
| 9 | |||
| 10 | namespace { | ||
| 11 | |||
| 12 | double IntegrandFunction(double x, double y, double z) { | ||
| 13 | 12700800 | return (x * y * z) + (x * x) + (y * y) + (z * z); | |
| 14 | } | ||
| 15 | |||
| 16 | 480 | double ComputeRectangleIntegral(int n, int step) { | |
| 17 | double result = 0.0; | ||
| 18 | 480 | int divisions = n * step; | |
| 19 | 480 | double h = 1.0 / divisions; | |
| 20 | |||
| 21 |
2/2✓ Branch 0 taken 10080 times.
✓ Branch 1 taken 480 times.
|
10560 | for (int i = 0; i < divisions; i++) { |
| 22 |
2/2✓ Branch 0 taken 321440 times.
✓ Branch 1 taken 10080 times.
|
331520 | for (int j = 0; j < divisions; j++) { |
| 23 |
2/2✓ Branch 0 taken 12700800 times.
✓ Branch 1 taken 321440 times.
|
13022240 | for (int k = 0; k < divisions; k++) { |
| 24 | 12700800 | double x = (i + 0.5) * h; | |
| 25 | 12700800 | double y = (j + 0.5) * h; | |
| 26 | 12700800 | double z = (k + 0.5) * h; | |
| 27 | 12700800 | result += IntegrandFunction(x, y, z) * h * h * h; | |
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | 480 | return result; | |
| 33 | } | ||
| 34 | |||
| 35 | } // namespace | ||
| 36 | |||
| 37 | 160 | KarpichIIntegralsMultistepRectangleSEQ::KarpichIIntegralsMultistepRectangleSEQ(const InType &in) { | |
| 38 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 39 | 160 | GetInput() = in; | |
| 40 | GetOutput() = 0; | ||
| 41 | 160 | } | |
| 42 | |||
| 43 | 160 | bool KarpichIIntegralsMultistepRectangleSEQ::ValidationImpl() { | |
| 44 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | if (GetInput() <= 0) { |
| 45 | return false; | ||
| 46 | } | ||
| 47 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | if (GetOutput() != 0) { |
| 48 | return false; | ||
| 49 | } | ||
| 50 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 160 times.
|
160 | if (GetInput() > 1000) { |
| 51 | ✗ | return false; | |
| 52 | } | ||
| 53 | if (GetStaticTypeOfTask() != ppc::task::TypeOfTask::kSEQ) { | ||
| 54 | return false; | ||
| 55 | } | ||
| 56 | return true; | ||
| 57 | } | ||
| 58 | |||
| 59 | 160 | bool KarpichIIntegralsMultistepRectangleSEQ::PreProcessingImpl() { | |
| 60 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | if (GetInput() <= 0) { |
| 61 | return false; | ||
| 62 | } | ||
| 63 | 160 | GetOutput() = 0; | |
| 64 | if (GetOutput() != 0) { | ||
| 65 | return false; | ||
| 66 | } | ||
| 67 | int divisions = GetInput() * 3; | ||
| 68 | 160 | return divisions > 0; | |
| 69 | } | ||
| 70 | |||
| 71 | 160 | bool KarpichIIntegralsMultistepRectangleSEQ::RunImpl() { | |
| 72 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | if (GetInput() == 0) { |
| 73 | return false; | ||
| 74 | } | ||
| 75 | |||
| 76 | 160 | double step1_result = ComputeRectangleIntegral(GetInput(), 1); | |
| 77 | 160 | double step2_result = ComputeRectangleIntegral(GetInput(), 2); | |
| 78 | 160 | double step3_result = ComputeRectangleIntegral(GetInput(), 3); | |
| 79 | |||
| 80 | 160 | double final_result = (step1_result + step2_result + step3_result) / 3.0; | |
| 81 | |||
| 82 | 160 | GetOutput() = static_cast<OutType>(std::round(final_result)); | |
| 83 | 160 | return GetOutput() > 0; | |
| 84 | } | ||
| 85 | |||
| 86 | 160 | bool KarpichIIntegralsMultistepRectangleSEQ::PostProcessingImpl() { | |
| 87 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | if (GetOutput() <= 0) { |
| 88 | return false; | ||
| 89 | } | ||
| 90 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | if (GetInput() <= 0) { |
| 91 | return false; | ||
| 92 | } | ||
| 93 | auto min_expected = static_cast<OutType>(1); | ||
| 94 | if (GetOutput() < min_expected) { | ||
| 95 | return false; | ||
| 96 | } | ||
| 97 | 160 | auto max_expected = static_cast<OutType>(GetInput() * GetInput() * GetInput() * 10); | |
| 98 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | if (GetOutput() > max_expected) { |
| 99 | return false; | ||
| 100 | } | ||
| 101 |
3/4✓ Branch 0 taken 8 times.
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
160 | if (GetOutput() == GetInput() && GetInput() > 1) { |
| 102 | ✗ | return false; | |
| 103 | } | ||
| 104 | return true; | ||
| 105 | } | ||
| 106 | |||
| 107 | } // namespace karpich_i_integrals_multistep_rectangle | ||
| 108 |