Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 7dc94eec authored by Théotime Grohens's avatar Théotime Grohens
Browse files

Add asserts to Fuzzy::add_point()

This commit adds asserts to ensure that the preconditions on
the points_ list are met when calling the function, namely:
- the list has at least two elements
- the first and last element are at abscissas X_MIN and X_MAX

Moreover, this commit moves the (p != points_.begin()) check
out of the if clause, and into an assert as well.

This ensures that if a bug happens here again, we will catch
it instead of sweeping it under the rug.
parent 9b3b9bf8
No related branches found
No related tags found
No related merge requests found
...@@ -478,7 +478,14 @@ void Fuzzy::clear() { ...@@ -478,7 +478,14 @@ void Fuzzy::clear() {
void Fuzzy::add_point(ProteinConcentration x, ProteinConcentration y) void Fuzzy::add_point(ProteinConcentration x, ProteinConcentration y)
{ {
// Don't add a new point if there's already a point at the same x. // points_ must always contain at least two elements, at X_MIN and X_MAX.
assert(points_.size() >= 2);
assert(points_.begin()->x == X_MIN);
assert(points_.rbegin()->x == X_MAX);
// We don't want to add a new point if there's already a point at the same x.
// To find out if there is such a point, we find the first point with
// larger x and then look at its predecessor.
list<Point>::iterator p = list<Point>::iterator p =
#ifndef __OPENMP_GPU #ifndef __OPENMP_GPU
find_if(points_.begin(), points_.end(), [x](Point& q){return q.x > x;}); find_if(points_.begin(), points_.end(), [x](Point& q){return q.x > x;});
...@@ -486,6 +493,11 @@ void Fuzzy::add_point(ProteinConcentration x, ProteinConcentration y) ...@@ -486,6 +493,11 @@ void Fuzzy::add_point(ProteinConcentration x, ProteinConcentration y)
algorithm_cuda::find_if_point_5(points_.begin(), points_.end(), x); algorithm_cuda::find_if_point_5(points_.begin(), points_.end(), x);
#endif #endif
// Since there is always a point at x = X_MAX, we always find such a point,
// and since there is always a point at x = X_MIN (which does not
// match the condition), that point always has a predecessor.
// p should therefore never be points_.begin().
assert(p != points_.begin());
if (prev(p)->x == x) { if (prev(p)->x == x) {
prev(p)->y += y; prev(p)->y += y;
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment