[yoda-svn] r261 - in trunk: . include/YODA tests

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed Aug 17 13:13:48 BST 2011


Author: mkawalec
Date: Wed Aug 17 13:13:48 2011
New Revision: 261

Log:
Added a Point3D test.

Added:
   trunk/tests/TestPoint3D.cc
Modified:
   trunk/configure.ac
   trunk/include/YODA/Point3D.h
   trunk/tests/Makefile.am
   trunk/tests/TestHisto2D.cc

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	Wed Aug 17 12:13:30 2011	(r260)
+++ trunk/configure.ac	Wed Aug 17 13:13:48 2011	(r261)
@@ -3,7 +3,7 @@
 AC_PREREQ(2.59)
 AC_INIT([YODA],[0.4.0beta0],[yoda at projects.hepforge.org],[YODA])
 AM_INIT_AUTOMAKE
-AC_CONFIG_SRCDIR([src/Bin1D.cc])
+#AC_CONFIG_SRCDIR([src/Bin1D.cc])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 AC_CONFIG_MACRO_DIR([m4])
 

Modified: trunk/include/YODA/Point3D.h
==============================================================================
--- trunk/include/YODA/Point3D.h	Wed Aug 17 12:13:30 2011	(r260)
+++ trunk/include/YODA/Point3D.h	Wed Aug 17 13:13:48 2011	(r261)
@@ -58,9 +58,13 @@
             const double& z,
             const std::pair<double,double>& ex,
             const std::pair<double,double>& ey,
-            const std::pair<double,double>& ez) {
-        Point3D(x, y, z, ex.first, ex.second, ey.first, ey.second, ez.first, ez.second);
-        }
+            const std::pair<double,double>& ez)
+      : _x(x), _y(y), _z(z)
+    {
+        _ex = ex;
+        _ey = ey;
+        _ez = ez;
+    }
 
 
     /// @todo Add copy constructor

Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am	Wed Aug 17 12:13:30 2011	(r260)
+++ trunk/tests/Makefile.am	Wed Aug 17 13:13:48 2011	(r261)
@@ -2,7 +2,8 @@
 	testweights	\
 	testhisto1Da testhisto1Db \
 	testprofile1Da \
-    testhisto2D  \
+  testhisto2D  \
+  testpoint3D  \
 	testindexedset testsortedvector
 
 AM_CPPFLAGS = -I$(top_srcdir)/include
@@ -15,6 +16,7 @@
 testindexedset_SOURCES = TestIndexedSet.cc
 testsortedvector_SOURCES = TestSortedVector.cc
 testhisto2D_SOURCES = TestHisto2D.cc
+testpoint3D_SOURCES = TestPoint3D.cc
 
 # TODO: Search paths are still not complete for the Python tests: need to add the lib.linux-i686-2.7 part to PYTHONPATH
 TESTS_ENVIRONMENT = \
@@ -26,6 +28,7 @@
 	testweights \
 	testhisto1Da testhisto1Db \
 	testprofile1Da \
-    testhisto2D    \
+  testhisto2D    \
+  testpoint3D    \
 	testindexedset testsortedvector \
 	test-yoda-1.py test-yoda-2.py

Modified: trunk/tests/TestHisto2D.cc
==============================================================================
--- trunk/tests/TestHisto2D.cc	Wed Aug 17 12:13:30 2011	(r260)
+++ trunk/tests/TestHisto2D.cc	Wed Aug 17 13:13:48 2011	(r261)
@@ -1,5 +1,6 @@
 #include "YODA/Histo2D.h"
 #include "YODA/Scatter3D.h"
+
 #include <cmath>
 #include <iostream>
 #include <unistd.h>

Added: trunk/tests/TestPoint3D.cc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/tests/TestPoint3D.cc	Wed Aug 17 13:13:48 2011	(r261)
@@ -0,0 +1,93 @@
+#include "YODA/Point3D.h"
+#include "YODA/Utils/MathUtils.h"
+
+#include <iostream>
+#include <sys/time.h>
+
+using namespace std;
+using namespace YODA;
+
+int main() {
+  cout << "-----------------------------------------------" << endl;
+  cout << "Creating a Point3D (empty constructor):" << endl;
+  Point3D p1();
+
+  cout << "Creating a Point3D (constructor with (double)values)" << endl;
+  Point3D p2(1, 2, 3);
+  cout << "Checking if everything was set correctly:" << endl;
+  cout << "x = " << p2.x() << ", y = " << p2.y() << ", z = " << p2.z() << endl;
+  
+  if(!fuzzyEquals(p2.x(), 1) || !fuzzyEquals(p2.y(), 2) || !fuzzyEquals(p2.z(), 3)){
+    cout << "One of the coordinates  was not set correctly!" << endl;
+    return -1;
+  }
+  if(!fuzzyEquals(p2.xErrMinus(), p2.xErrPlus()) || 
+     !fuzzyEquals(p2.xErrPlus(), p2.yErrMinus()) ||
+     !fuzzyEquals(p2.yErrMinus(), p2.yErrPlus()) ||
+     !fuzzyEquals(p2.yErrPlus(), p2.zErrMinus()) ||
+     !fuzzyEquals(p2.zErrMinus(), p2.zErrPlus()) ||
+     !fuzzyEquals(p2.zErrPlus(), 0)) {
+    cout << "Errors were not set correctly!" << endl;
+    return -1;
+}
+
+  cout << "Creating a Point3D (constructor with explicit assymetric errors)" << endl;
+  Point3D p3(1, 2, 3, 1, 2, 1, 2, 1, 2);
+  
+  cout << "Checking if everything was set correctly:" << endl;
+  cout << "x = " << p3.x() << ", y = " << p3.y() << ", z = " << p3.z() << endl;
+
+  if(!fuzzyEquals(p3.x(), 1) || !fuzzyEquals(p3.y(), 2) || !fuzzyEquals(p3.z(), 3)){
+    cout << "One of the coordinates  was not set correctly!" << endl;
+    return -1;
+  }
+  if(!fuzzyEquals(p3.xErrMinus(), 1) || 
+     !fuzzyEquals(p3.xErrPlus(), 2) ||
+     !fuzzyEquals(p3.yErrMinus(), 1) ||
+     !fuzzyEquals(p3.yErrPlus(), 2) ||
+     !fuzzyEquals(p3.zErrMinus(), 1) ||
+     !fuzzyEquals(p3.zErrPlus(), 2)) {
+    cout << "Errors were not set correctly!" << endl;
+    return -1;
+}
+
+  cout << "Creating a Point3D (constructor with assymetric, std::pair errrors)" << endl;
+  pair<double, double> err = make_pair(1, 2);
+  Point3D p4(1, 2, 3, err, err, err);
+
+  cout << "Checking if everything was set correctly:" << endl;
+  cout << "x = " << p4.x() << ", y = " << p4.y() << ", z = " << p4.z() << endl;
+
+  if(!fuzzyEquals(p4.x(), 1) || !fuzzyEquals(p4.y(), 2) || !fuzzyEquals(p4.z(), 3)){
+    cout << "One of the coordinates  was not set correctly!" << endl;
+    return -1;
+  }
+  if(!fuzzyEquals(p4.xErrMinus(), 1) || 
+     !fuzzyEquals(p4.xErrPlus(), 2) ||
+     !fuzzyEquals(p4.yErrMinus(), 1) ||
+     !fuzzyEquals(p4.yErrPlus(), 2) ||
+     !fuzzyEquals(p4.zErrMinus(), 1) ||
+     !fuzzyEquals(p4.zErrPlus(), 2)) {
+    cout << "Errors were not set correctly!" << endl;
+    return -1;
+
+}
+
+  cout << "And a quick performance check: " << endl;
+  struct timeval startTime;
+  struct timeval endTime;
+
+  size_t num = 100000;
+  Point3D points[num];
+  gettimeofday(&startTime, NULL);
+  for(size_t i = 0; i < num; i++) points[i] =  Point3D(1, 1, 1, 1, 2, 1, 2, 1, 2);
+  gettimeofday(&endTime, NULL);
+
+  double tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000;
+  double tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000;
+  cout << "Time to make 100k Points3D is: " << tE - tS << "s" << endl;
+
+
+  cout << "-----------------------------------------------" << endl;
+  return EXIT_SUCCESS;
+}


More information about the yoda-svn mailing list