[yoda-svn] r368 - in trunk: include/YODA tests/Histo1D

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Fri Aug 26 11:41:56 BST 2011


Author: mkawalec
Date: Fri Aug 26 11:41:56 2011
New Revision: 368

Log:
Added Histo1D files not added previously.

Added:
   trunk/tests/Histo1D/H1DCreate.cc
   trunk/tests/Histo1D/H1DFill.cc
   trunk/tests/Histo1D/H1DModify.cc
Modified:
   trunk/include/YODA/Axis2D.h

Modified: trunk/include/YODA/Axis2D.h
==============================================================================
--- trunk/include/YODA/Axis2D.h	Thu Aug 25 15:05:12 2011	(r367)
+++ trunk/include/YODA/Axis2D.h	Fri Aug 26 11:41:56 2011	(r368)
@@ -10,6 +10,7 @@
 
 #include <algorithm>
 #include <limits>
+#include <vector>
 
 namespace YODA {
 

Added: trunk/tests/Histo1D/H1DCreate.cc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/tests/Histo1D/H1DCreate.cc	Fri Aug 26 11:41:56 2011	(r368)
@@ -0,0 +1,77 @@
+#include "YODA/Histo1D.h"
+#include "YODA/Utils/MathUtils.h"
+
+#include <iostream>
+#include <cmath>
+
+using namespace YODA;
+using namespace std;
+
+int main() {
+  cout << "--------------------" << endl;
+  cout << "Testing constructors: " << endl;
+
+  cout << "The most basic, linear constructor.      ";
+  Histo1D h(100, 0, 100);
+  if (h.numBins() != 100) {
+    cout << "FAIL" << endl << "Wrong number of bins was created!" << endl;
+    return -1;
+  }
+  if (h.lowEdge() != 0) {
+    cout << "FAIL" << endl << "Low edge wasn't properly set!" << endl;
+    return -1;
+  }
+  if (h.highEdge() != 100) {
+    cout << "FAIL" << endl << "High edge wasn't properly set!" << endl;
+    return -1;
+  }
+  if (!fuzzyEquals(h.integral(), 0)) {
+    cout << "FAIL" << endl << "The constructor is setting some statistics!" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Explicit bin edges constructor:          ";
+  vector<double> edges;
+  for (int i = 0; i < 101; ++i) edges.push_back(i);
+  Histo1D h1(edges);
+  if (h1.numBins() != 100) {
+    cout << "FAIL" << endl << "Wrong number of bins was created!" << endl;
+    return -1;
+  }
+  if (h1.lowEdge() != 0) {
+    cout << "FAIL" << endl << "Low edge wasn't properly set!" << endl;
+    return -1;
+  }
+  if (h1.highEdge() != 100) {
+    cout << "FAIL" << endl << "High edge wasn't properly set!" << endl;
+    return -1;
+  }
+  if (!fuzzyEquals(h1.integral(), 0)) {
+    cout << "FAIL" << endl << "The constructor is setting some statistics!" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Copy constructor:                        ";
+  Histo1D h2(h);
+  if (h2.numBins() != 100) {
+    cout << "FAIL" << endl << "Wrong number of bins was created!" << endl;
+    return -1;
+  }
+  if (h2.lowEdge() != 0) {
+    cout << "FAIL" << endl << "Low edge wasn't properly set!" << endl;
+    return -1;
+  }
+  if (h2.highEdge() != 100) {
+    cout << "FAIL" << endl << "High edge wasn't properly set!" << endl;
+    return -1;
+  }
+  if (!fuzzyEquals(h2.integral(), 0)) {
+    cout << "FAIL" << endl << "The constructor is setting some statistics!" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  return EXIT_SUCCESS;
+}

Added: trunk/tests/Histo1D/H1DFill.cc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/tests/Histo1D/H1DFill.cc	Fri Aug 26 11:41:56 2011	(r368)
@@ -0,0 +1,74 @@
+#include "YODA/Histo1D.h"
+
+#include <iostream>
+using namespace std;
+using namespace YODA;
+
+int main() {
+  /// Creating a histo:
+  Histo1D h(100, 0, 100);
+  
+  cout << "Trying to fill the sample histogram:     ";
+  h.fill(0,2);
+  cout << "PASS" << endl;
+  
+  cout << "Checking sumW:                           ";
+  if(h.sumW() != 2) {
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+  
+  cout << "Checking sumW2:                          ";
+  if(h.sumW2() != 4) {
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+  
+
+  h.fill(10, 2);
+
+  cout << "Checking mean:                           ";
+  if(!fuzzyEquals(5, h.mean(false))) {
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Checking variance:                       ";
+  if(!fuzzyEquals(25, h.variance(false))){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+  
+  cout << "Checking standard deviation:             ";
+  if(!fuzzyEquals(5, h.stdDev(false))){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Trying to fill the underflow:            ";
+  h.fill(-10,1);
+  cout << "PASS" << endl;
+  cout << "Checking if stats were set correctly:    ";
+  if(!fuzzyEquals(h.underflow().mean(), -10)) {
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Trying to fill the overflow:             ";
+  h.fill(110,1);
+  cout << "PASS" << endl;
+  cout << "Checking if stats were set correctly:    ";
+  if(!fuzzyEquals(h.overflow().mean(), 110)) {
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  return EXIT_SUCCESS;
+}

Added: trunk/tests/Histo1D/H1DModify.cc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/tests/Histo1D/H1DModify.cc	Fri Aug 26 11:41:56 2011	(r368)
@@ -0,0 +1,69 @@
+#include "YODA/Histo1D.h"
+
+#include <iostream>
+using namespace std;
+using namespace YODA;
+
+int main() {
+  
+  Histo1D h(100, 0, 100);
+  cout << "Trying to merge bins:                    ";
+  h.mergeBins(0, 10);
+  cout << "PASS" << endl;
+
+  cout << "Testing if bin nuber was updated:        ";
+  if(h.numBins() != 90) {
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+  
+  cout << "Checking if bin size was updated:        ";
+  if(!fuzzyEquals(h.bin(0).xMin(), 0) || !fuzzyEquals(h.bin(0).xMax(),11)){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  
+  
+  cout << "Checking if bin removal works:           ";
+  h.eraseBin(0);
+  cout << "PASS" << endl;
+  
+  cout << "Was the bin number updated properly?     ";
+  if(h.numBins() != 89) {
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Was the right bin removed?               ";
+  if(fuzzyEquals(h.bin(0).xMin(), 0) && fuzzyEquals(h.bin(0).xMax(), 11)){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+
+  cout << "Checking if it is possible to add a bin: ";
+  h.addBin(0,11);
+  cout << "PASS" << endl;
+ 
+  cout << "Checking if it was added properly:       ";
+  if(!fuzzyEquals(h.binByCoord(1).xMin(), 0) || !fuzzyEquals(h.binByCoord(1).xMax(),11)){
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  cout << "Checking the reset fuction:              ";
+  h.reset();
+  if(!(h.mean() != h.mean())|| !(h.mean(false) != h.mean(false))) {
+    cout << "FAIL" << endl;
+    return -1;
+  }
+  cout << "PASS" << endl;
+
+  return EXIT_SUCCESS;
+}


More information about the yoda-svn mailing list