From fa284dcb218611528fc44e9634385e0c1ebc347c Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Thu, 13 Nov 2014 16:59:04 +0100 Subject: [PATCH] Fix cppcheck warnings. --- tests/test-distribution.cc | 2 +- tests/test-statistics.cc | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/test-distribution.cc b/tests/test-distribution.cc index ea76fe8..2fa9077 100644 --- a/tests/test-distribution.cc +++ b/tests/test-distribution.cc @@ -46,7 +46,7 @@ int main () for (size_t i = 0; i < p.size (); i++) if (p[i] - (double)(weight[i] / (double)total_weight) > DBL_EPSILON - || p[i] - (double)(weight[i] / (double)total_weight) > DBL_EPSILON) { + || - p[i] + (double)(weight[i] / (double)total_weight) > DBL_EPSILON) { std::cout << "p[" << i << "] = " << p[i] << std::endl << "weight[" << i << "] = " << weight[i] << std::endl << "Total weight = " << total_weight << std::endl diff --git a/tests/test-statistics.cc b/tests/test-statistics.cc index 26b52e1..786f839 100644 --- a/tests/test-statistics.cc +++ b/tests/test-statistics.cc @@ -35,7 +35,7 @@ class TestBin : public Bin { { os << val << " has :"; for (std::list <double>::const_iterator it = l.begin (); - it != l.end (); it++) + it != l.end (); ++it) os << " " << *it << std::endl; return os << std::endl; } @@ -64,16 +64,22 @@ int main () TestStatistics t; double *check = new double [100]; + int status = EXIT_SUCCESS; for (int i = 0; i < 100; i++) { check[i] = ((double)(rand())/(double)rand()); t.add (i, check[i]); } for (int i = 0; i < 100; i++) { TestStatistics::const_iterator it = t.find (i); - if (it == t.end ()) - return EXIT_FAILURE; - if (it->l.size () != 1 && check[i] != it->l.front()) - return EXIT_FAILURE; + if (it == t.end ()) { + status = EXIT_FAILURE; + break; + } + if (it->l.size () != 1 && check[i] != it->l.front()) { + status = EXIT_FAILURE; + break; + } } - return EXIT_SUCCESS; + delete[] check; + return status; } -- GitLab