| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "frolova_s_mult_int_trapez/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstddef> | ||
| 5 | // #include <iostream> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "frolova_s_mult_int_trapez/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace frolova_s_mult_int_trapez { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | FrolovaSMultIntTrapezSEQ::FrolovaSMultIntTrapezSEQ(const InType &in) |
| 13 |
3/6✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 48 times.
✗ Branch 8 not taken.
|
48 | : limits_(in.limits), number_of_intervals_(in.number_of_intervals) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | GetInput() = in; |
| 16 | 48 | GetOutput() = 0.0; | |
| 17 | 48 | } | |
| 18 | |||
| 19 | 519888 | unsigned int FrolovaSMultIntTrapezSEQ::CalculationOfCoefficient(const std::vector<double> &point) { | |
| 20 | 519888 | auto degree = static_cast<unsigned int>(limits_.size()); | |
| 21 |
2/2✓ Branch 0 taken 1514816 times.
✓ Branch 1 taken 519888 times.
|
2034704 | for (unsigned int i = 0; i < limits_.size(); i++) { |
| 22 |
4/4✓ Branch 0 taken 1467040 times.
✓ Branch 1 taken 47776 times.
✓ Branch 2 taken 47776 times.
✓ Branch 3 taken 1419264 times.
|
1514816 | if ((limits_[i].first == point[i]) || (limits_[i].second == point[i])) { |
| 23 | 95552 | degree--; | |
| 24 | } | ||
| 25 | } | ||
| 26 | 519888 | return static_cast<unsigned int>(std::pow(2.0, static_cast<double>(degree))); | |
| 27 | } | ||
| 28 | |||
| 29 | 519888 | void FrolovaSMultIntTrapezSEQ::Recursive(std::vector<double> &point, unsigned int &definition) { | |
| 30 | 519888 | unsigned int temp_def = definition; | |
| 31 | |||
| 32 | 519888 | std::vector<unsigned int> divisors(limits_.size(), 1); | |
| 33 |
2/2✓ Branch 0 taken 1514816 times.
✓ Branch 1 taken 519888 times.
|
2034704 | for (unsigned int i = 0; i < limits_.size(); i++) { |
| 34 |
2/2✓ Branch 0 taken 994928 times.
✓ Branch 1 taken 519888 times.
|
1514816 | if (i > 0) { |
| 35 | 994928 | divisors[i] = divisors[i - 1] * (number_of_intervals_[i - 1] + 1); | |
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 1514816 times.
✓ Branch 1 taken 519888 times.
|
2034704 | for (int i = static_cast<int>(limits_.size()) - 1; i >= 0; i--) { |
| 40 | 1514816 | const auto quotient = temp_def / divisors[i]; | |
| 41 | 1514816 | point[i] = limits_[i].first + (static_cast<double>(quotient) * (limits_[i].second - limits_[i].first) / | |
| 42 | 1514816 | static_cast<double>(number_of_intervals_[i])); | |
| 43 | 1514816 | temp_def = temp_def % divisors[i]; | |
| 44 | } | ||
| 45 | |||
| 46 |
1/2✓ Branch 0 taken 519888 times.
✗ Branch 1 not taken.
|
519888 | definition = temp_def; |
| 47 | 519888 | } | |
| 48 | |||
| 49 | 519888 | std::vector<double> FrolovaSMultIntTrapezSEQ::GetPointFromNumber(unsigned int number) { | |
| 50 | 519888 | std::vector<double> point(limits_.size()); | |
| 51 |
1/2✓ Branch 0 taken 519888 times.
✗ Branch 1 not taken.
|
519888 | unsigned int definition = number; |
| 52 | |||
| 53 |
1/2✓ Branch 0 taken 519888 times.
✗ Branch 1 not taken.
|
519888 | if (!limits_.empty()) { |
| 54 |
1/2✓ Branch 1 taken 519888 times.
✗ Branch 2 not taken.
|
519888 | Recursive(point, definition); |
| 55 | } | ||
| 56 | |||
| 57 | 519888 | return point; | |
| 58 | } | ||
| 59 | |||
| 60 | 48 | bool FrolovaSMultIntTrapezSEQ::ValidationImpl() { | |
| 61 | 48 | auto input = GetInput(); | |
| 62 | |||
| 63 |
2/4✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
|
48 | if (input.limits.empty() || input.number_of_intervals.empty()) { |
| 64 | return false; | ||
| 65 | } | ||
| 66 | |||
| 67 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (input.limits.size() != input.number_of_intervals.size()) { |
| 68 | return false; | ||
| 69 | } | ||
| 70 | |||
| 71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (!input.function) { |
| 72 | return false; | ||
| 73 | } | ||
| 74 | |||
| 75 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
|
144 | for (size_t i = 0; i < input.limits.size(); i++) { |
| 76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | if (input.limits[i].first >= input.limits[i].second) { |
| 77 | return false; | ||
| 78 | } | ||
| 79 | |||
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | if (input.number_of_intervals[i] == 0) { |
| 81 | return false; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | return true; | ||
| 86 | 48 | } | |
| 87 | |||
| 88 | 48 | bool FrolovaSMultIntTrapezSEQ::PreProcessingImpl() { | |
| 89 | 48 | auto input = GetInput(); | |
| 90 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | limits_ = input.limits; |
| 91 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | number_of_intervals_ = input.number_of_intervals; |
| 92 | 48 | result_ = 0.0; | |
| 93 | |||
| 94 | 48 | return true; | |
| 95 | 48 | } | |
| 96 | |||
| 97 | 48 | bool FrolovaSMultIntTrapezSEQ::RunImpl() { | |
| 98 | unsigned int count = 1; | ||
| 99 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
|
144 | for (auto number_of_interval : number_of_intervals_) { |
| 100 | 96 | count *= (number_of_interval + 1); | |
| 101 | } | ||
| 102 | |||
| 103 |
2/2✓ Branch 0 taken 519888 times.
✓ Branch 1 taken 48 times.
|
519936 | for (unsigned int i = 0; i < count; i++) { |
| 104 | 519888 | std::vector<double> point = GetPointFromNumber(i); | |
| 105 |
3/8✓ Branch 2 taken 519888 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 519888 times.
✓ Branch 6 taken 519888 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
1039776 | result_ += static_cast<double>(CalculationOfCoefficient(point)) * GetInput().function(point); |
| 106 | } | ||
| 107 | |||
| 108 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
|
144 | for (unsigned int i = 0; i < limits_.size(); i++) { |
| 109 | 96 | result_ *= (limits_[i].second - limits_[i].first) / static_cast<double>(number_of_intervals_[i]); | |
| 110 | } | ||
| 111 | |||
| 112 | 48 | result_ /= std::pow(2.0, static_cast<double>(limits_.size())); | |
| 113 | |||
| 114 | 48 | return true; | |
| 115 | } | ||
| 116 | |||
| 117 | 48 | bool FrolovaSMultIntTrapezSEQ::PostProcessingImpl() { | |
| 118 | 48 | GetOutput() = result_; | |
| 119 | |||
| 120 | 48 | return true; | |
| 121 | } | ||
| 122 | |||
| 123 | } // namespace frolova_s_mult_int_trapez | ||
| 124 |