• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

BlueBrain / MorphIO / 6533524408

16 Oct 2023 12:24PM UTC coverage: 76.051% (-0.02%) from 76.073%
6533524408

push

github

mgeplf
fix test_root_node_split

1972 of 2593 relevant lines covered (76.05%)

903.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.39
/src/properties.cpp
1
/* Copyright (c) 2013-2023, EPFL/Blue Brain Project
2
 *
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
#include <algorithm>
6

7
#include <morphio/errorMessages.h>
8
#include <morphio/properties.h>
9
#include <morphio/vector_types.h>
10

11
#include "point_utils.h"
12
#include "shared_utils.hpp"
13

14
namespace morphio {
15
namespace Property {
16

17
namespace details {
18
static bool compare_section_structure(const std::vector<Section::Type>& vec1,
16✔
19
                                      const std::vector<Section::Type>& vec2,
20
                                      const std::string& name,
21
                                      LogLevel logLevel) {
22
    if (vec1.size() != vec2.size()) {
16✔
23
        if (logLevel > LogLevel::ERROR) {
12✔
24
            printError(Warning::UNDEFINED,
6✔
25
                       "Error comparing " + name + ", size differs: " +
12✔
26
                           std::to_string(vec1.size()) + " vs " + std::to_string(vec2.size()));
24✔
27
        }
28
        return false;
12✔
29
    }
30

31
    for (unsigned int i = 1; i < vec1.size(); ++i) {
16✔
32
        if (vec1[i][0] - vec1[1][0] != vec2[i][0] - vec2[1][0] || vec1[i][1] != vec2[i][1]) {
12✔
33
            if (logLevel > LogLevel::ERROR) {
×
34
                printError(Warning::UNDEFINED, "Error comparing " + name + ", elements differ:");
×
35
                printError(Warning::UNDEFINED,
×
36
                           std::to_string(vec1[i][0] - vec1[1][0]) + ", " +
×
37
                               std::to_string(vec1[i][1]) + " <--> " +
×
38
                               std::to_string(vec2[i][0] - vec2[1][0]) + ", " +
×
39
                               std::to_string(vec2[i][1]));
×
40
            }
41
            return false;
×
42
        }
43
    }
44

45
    return true;
4✔
46
}
47

48
}  // namespace details
49

50
PointLevel::PointLevel(std::vector<Point::Type> points,
2,084✔
51
                       std::vector<Diameter::Type> diameters,
52
                       std::vector<Perimeter::Type> perimeters)
2,084✔
53
    : _points(std::move(points))
2,084✔
54
    , _diameters(std::move(diameters))
2,084✔
55
    , _perimeters(std::move(perimeters)) {
2,102✔
56
    if (_points.size() != _diameters.size()) {
2,084✔
57
        throw SectionBuilderError(
58
            "Point vector have size: " + std::to_string(_points.size()) +
8✔
59
            " while Diameter vector has size: " + std::to_string(_diameters.size()));
12✔
60
    }
61

62
    if (!_perimeters.empty() && _points.size() != _perimeters.size()) {
2,080✔
63
        throw SectionBuilderError(
64
            "Point vector have size: " + std::to_string(_points.size()) +
4✔
65
            " while Perimeter vector has size: " + std::to_string(_perimeters.size()));
6✔
66
    }
67
}
2,078✔
68

69
PointLevel::PointLevel(const PointLevel& data)
2,074✔
70
    : PointLevel(data._points, data._diameters, data._perimeters) {}
2,074✔
71

72
PointLevel::PointLevel(const PointLevel& data, SectionRange range) {
268✔
73
    _points = copySpan<Property::Point>(data._points, range);
268✔
74
    _diameters = copySpan<Property::Diameter>(data._diameters, range);
268✔
75
    _perimeters = copySpan<Property::Perimeter>(data._perimeters, range);
268✔
76
}
268✔
77

78
PointLevel& PointLevel::operator=(const PointLevel& other) {
56✔
79
    if (&other == this) {
56✔
80
        return *this;
×
81
    }
82

83
    _points = other._points;
56✔
84
    _diameters = other._diameters;
56✔
85
    _perimeters = other._perimeters;
56✔
86

87
    return *this;
56✔
88
}
89

90
bool SectionLevel::diff(const SectionLevel& other, LogLevel logLevel) const {
10✔
91
    return !(this == &other ||
18✔
92
             (details::compare_section_structure(
26✔
93
                  this->_sections, other._sections, "_sections", logLevel) &&
8✔
94
              morphio::property::compare(
18✔
95
                  this->_sectionTypes, other._sectionTypes, "_sectionTypes", logLevel) &&
4✔
96
              morphio::property::compare(this->_children, other._children, "_children", logLevel)));
20✔
97
}
98

99
bool SectionLevel::operator==(const SectionLevel& other) const {
2✔
100
    return !diff(other, LogLevel::ERROR);
2✔
101
}
102

103
bool SectionLevel::operator!=(const SectionLevel& other) const {
4✔
104
    return diff(other, LogLevel::ERROR);
4✔
105
}
106

107
bool CellLevel::diff(const CellLevel& other, LogLevel logLevel) const {
12✔
108
    if (this == &other) {
12✔
109
        return false;
4✔
110
    }
111

112
    if (logLevel > 0 && this->_cellFamily != other._cellFamily) {
8✔
113
        std::cout << "this->_cellFamily: " << this->_cellFamily << '\n'
2✔
114
                  << "other._cellFamily: " << other._cellFamily << '\n';
2✔
115
    }
116
    return !(this->_cellFamily == other._cellFamily && this->_somaType == other._somaType);
8✔
117
}
118

119
bool CellLevel::operator==(const CellLevel& other) const {
2✔
120
    return !diff(other, LogLevel::ERROR);
2✔
121
}
122

123
bool CellLevel::operator!=(const CellLevel& other) const {
6✔
124
    return diff(other, LogLevel::ERROR);
6✔
125
}
126

127
MitochondriaPointLevel::MitochondriaPointLevel(const MitochondriaPointLevel& data,
66✔
128
                                               const SectionRange& range) {
66✔
129
    _sectionIds = copySpan<Property::MitoNeuriteSectionId>(data._sectionIds, range);
66✔
130
    _relativePathLengths = copySpan<Property::MitoPathLength>(data._relativePathLengths, range);
66✔
131
    _diameters = copySpan<Property::MitoDiameter>(data._diameters, range);
66✔
132
}
66✔
133

134
MitochondriaPointLevel::MitochondriaPointLevel(
6✔
135
    std::vector<MitoNeuriteSectionId::Type> sectionIds,
136
    std::vector<MitoPathLength::Type> relativePathLengths,
137
    std::vector<MitoDiameter::Type> diameters)
6✔
138
    : _sectionIds(std::move(sectionIds))
6✔
139
    , _relativePathLengths(std::move(relativePathLengths))
6✔
140
    , _diameters(std::move(diameters)) {
18✔
141
    if (_sectionIds.size() != _relativePathLengths.size()) {
6✔
142
        throw SectionBuilderError(
143
            "While building MitochondriaPointLevel:\n"
144
            "section IDs vector have size: " +
2✔
145
            std::to_string(_sectionIds.size()) + " while relative path length vector has size: " +
6✔
146
            std::to_string(_relativePathLengths.size()));
6✔
147
    }
148

149
    if (_sectionIds.size() != _diameters.size()) {
4✔
150
        throw SectionBuilderError(
151
            "While building MitochondriaPointLevel:\n"
152
            "section IDs vector have size: " +
2✔
153
            std::to_string(_sectionIds.size()) +
6✔
154
            " while diameter vector has size: " + std::to_string(_diameters.size()));
6✔
155
    }
156
}
2✔
157

158
bool MitochondriaSectionLevel::diff(const MitochondriaSectionLevel& other,
10✔
159
                                    LogLevel logLevel) const {
160
    return !(this == &other ||
18✔
161
             (details::compare_section_structure(
26✔
162
                  this->_sections, other._sections, "_sections", logLevel) &&
8✔
163
              morphio::property::compare(this->_children, other._children, "_children", logLevel)));
20✔
164
}
165

166
bool MitochondriaSectionLevel::operator==(const MitochondriaSectionLevel& other) const {
2✔
167
    return !diff(other, LogLevel::ERROR);
2✔
168
}
169

170
bool MitochondriaSectionLevel::operator!=(const MitochondriaSectionLevel& other) const {
4✔
171
    return diff(other, LogLevel::ERROR);
4✔
172
}
173

174
bool MitochondriaPointLevel::diff(const MitochondriaPointLevel& other, LogLevel logLevel) const {
4✔
175
    return !(this == &other ||
4✔
176
             (morphio::property::compare(
4✔
177
                  this->_sectionIds, other._sectionIds, "mito section ids", logLevel) &&
×
178
              morphio::property::compare(this->_relativePathLengths,
4✔
179
                                         other._relativePathLengths,
×
180
                                         "mito relative pathlength",
181
                                         logLevel) &&
×
182
              morphio::property::compare(
4✔
183
                  this->_diameters, other._diameters, "mito section diameters", logLevel)));
8✔
184
}
185

186
bool MitochondriaPointLevel::operator==(const MitochondriaPointLevel& other) const {
2✔
187
    return !diff(other, LogLevel::ERROR);
2✔
188
}
189

190
bool MitochondriaPointLevel::operator!=(const MitochondriaPointLevel& other) const {
2✔
191
    return diff(other, LogLevel::ERROR);
2✔
192
}
193

194
std::ostream& operator<<(std::ostream& os, const PointLevel& pointLevel) {
4✔
195
    os << "Point level properties:\n"
196
       << "Point Diameter"
197
       << (pointLevel._perimeters.size() == pointLevel._points.size() ? " Perimeter\n" : "\n");
4✔
198
    for (unsigned int i = 0; i < pointLevel._points.size(); ++i) {
12✔
199
        os << dumpPoint(pointLevel._points[i]) << ' ' << pointLevel._diameters[i];
8✔
200
        if (pointLevel._perimeters.size() == pointLevel._points.size()) {
8✔
201
            os << ' ' << pointLevel._perimeters[i];
8✔
202
        }
203
        os << '\n';
8✔
204
    }
205
    return os;
4✔
206
}
207

208
std::ostream& operator<<(std::ostream& os, const Properties& properties) {
×
209
    os << properties._pointLevel << '\n';
×
210
    // os << _sectionLevel << '\n';
211
    // os << _cellLevel << '\n';
212
    return os;
×
213
}
214

215
}  // namespace Property
216
}  // namespace morphio
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc