Skip to content
Snippets Groups Projects
Commit 03f78a30 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add a test

parent a5c00e30
No related merge requests found
......@@ -40,3 +40,4 @@ ENDMACRO(ADD_TESTCASE)
ADD_TESTCASE (test-successstatistics FALSE)
ADD_TESTCASE (test-distribution FALSE)
ADD_TESTCASE (test-statistics FALSE)
// Copyright (c) 2014, LAAS-CNRS
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
//
// This file is part of hpp-statistics.
// hpp-statistics is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// hpp-statistics is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// hpp-statistics. If not, see <http://www.gnu.org/licenses/>.
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <list>
#include "hpp/statistics/bin.hh"
using hpp::statistics::Bin;
using hpp::statistics::Statistics;
class TestBin : public Bin {
public:
int val;
std::list < double > l;
TestBin (int i) : val (i) {}
std::ostream& printValue (std::ostream& os) const
{
os << val << " has :";
for (std::list <double>::const_iterator it = l.begin ();
it != l.end (); it++)
os << " " << *it << std::endl;
return os << std::endl;
}
bool operator< (const TestBin& rhs) const {
return val < rhs.val;
}
bool operator== (const TestBin& rhs) const {
return val == rhs.val;
}
};
class TestStatistics : public Statistics <TestBin> {
public:
void add (int n, double d) {
TestBin b(n);
TestStatistics::iterator it = insert (b);
it->l.push_back (d);
}
};
int main ()
{
srand (time(NULL));
TestStatistics t;
double *check = new double [100];
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;
}
return EXIT_SUCCESS;
}
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