[yoda-svn] r460 - in trunk: include/YODA/Utils tests/Histo1D tests/Profile1D

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed May 2 20:32:42 BST 2012


Author: buckley
Date: Wed May  2 20:32:42 2012
New Revision: 460

Log:
Padding tweaks

Modified:
   trunk/include/YODA/Utils/Formatting.h
   trunk/tests/Histo1D/H1DModify.cc
   trunk/tests/Profile1D/P1DModify.cc

Modified: trunk/include/YODA/Utils/Formatting.h
==============================================================================
--- trunk/include/YODA/Utils/Formatting.h	Wed May  2 20:13:44 2012	(r459)
+++ trunk/include/YODA/Utils/Formatting.h	Wed May  2 20:32:42 2012	(r460)
@@ -2,13 +2,14 @@
 #define YODA_FORMATTING_H
 
 #include <iostream>
+#include <iomanip>
 #include <unistd.h>
 
-
 #define MSG_(msg) do { std::cout << msg; } while (0)
 
 #define MSG(msg) MSG_(msg << std::endl)
 
+#define PAD(n) std::setw(n) << std::left
 
 #define COLOR_(msg, code) \
   (isatty(1) ? code : "") << msg << (isatty(1) ? "\033[0m" : "")

Modified: trunk/tests/Histo1D/H1DModify.cc
==============================================================================
--- trunk/tests/Histo1D/H1DModify.cc	Wed May  2 20:13:44 2012	(r459)
+++ trunk/tests/Histo1D/H1DModify.cc	Wed May  2 20:32:42 2012	(r460)
@@ -1,69 +1,69 @@
 #include "YODA/Histo1D.h"
+#include "YODA/Utils/Formatting.h"
 
-#include <iostream>
-using namespace std;
 using namespace YODA;
+using namespace std;
 
 int main() {
-  
+
+  MSG_(PAD(70) << "Setting up a 100 bin histo from 0-100: ");
   Histo1D h(100, 0, 100);
-  cout << "Trying to merge bins:                    ";
+  MSG_GREEN("PASS");
+
+  MSG_(PAD(70) << "Trying to merge bins: ");
   h.mergeBins(0, 10);
-  cout << "PASS" << endl;
+  MSG_GREEN("PASS");
 
-  cout << "Testing if bin nuber was updated:        ";
-  if(h.numBins() != 90) {
-    cout << "FAIL" << endl;
+  MSG_(PAD(70) << "Testing if bin number was updated: ");
+  if (h.numBins() != 90) {
+    MSG_RED("FAIL");
     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;
+  MSG_GREEN("PASS");
+
+  MSG_(PAD(70) << "Checking if bin size was updated: ");
+  if (!fuzzyEquals(h.bin(0).xMin(), 0) || !fuzzyEquals(h.bin(0).xMax(), 11)) {
+    MSG_RED("FAIL");
     return -1;
   }
-  cout << "PASS" << endl;
+  MSG_GREEN("PASS");
 
-  
-  
-  cout << "Checking if bin removal works:           ";
+  MSG_(PAD(70) << "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;
+  MSG_GREEN("PASS");
+
+  MSG_(PAD(70) << "Was the bin number updated properly? ");
+  if (h.numBins() != 89) {
+    MSG_RED("FAIL");
     return -1;
   }
-  cout << "PASS" << endl;
+  MSG_GREEN("PASS");
 
-  cout << "Was the right bin removed?               ";
-  if(fuzzyEquals(h.bin(0).xMin(), 0) && fuzzyEquals(h.bin(0).xMax(), 11)){
-    cout << "FAIL" << endl;
+  MSG_(PAD(70) << "Was the right bin removed? ");
+  if (fuzzyEquals(h.bin(0).xMin(), 0) && fuzzyEquals(h.bin(0).xMax(), 11)) {
+    MSG_RED("FAIL");
     return -1;
   }
-  cout << "PASS" << endl;
+  MSG_GREEN("PASS");
 
+  MSG_(PAD(70) << "Checking if it is possible to add a bin: ");
+  h.addBin(0, 10.9);
+  MSG_GREEN("PASS");
 
-  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;
+  MSG_(PAD(70) << "Checking if it was added properly: ");
+  if (!fuzzyEquals(h.binByCoord(1).xMin(), 0) || !fuzzyEquals(h.binByCoord(1).xMax(),11)) {
+    MSG_RED("FAIL");
     return -1;
   }
-  cout << "PASS" << endl;
+  MSG_GREEN("PASS");
 
-  cout << "Checking the reset fuction:              ";
+  MSG_(PAD(70) << "Checking the reset function: ");
   h.reset();
-  if(!(h.mean() != h.mean())|| !(h.mean(false) != h.mean(false))) {
-    cout << "FAIL" << endl;
+  if (!(h.mean() != h.mean())|| !(h.mean(false) != h.mean(false))) {
+    MSG_RED("FAIL");
     return -1;
   }
-  cout << "PASS" << endl;
+  MSG_GREEN("PASS");
 
   return EXIT_SUCCESS;
 }

Modified: trunk/tests/Profile1D/P1DModify.cc
==============================================================================
--- trunk/tests/Profile1D/P1DModify.cc	Wed May  2 20:13:44 2012	(r459)
+++ trunk/tests/Profile1D/P1DModify.cc	Wed May  2 20:32:42 2012	(r460)
@@ -7,12 +7,12 @@
 int main() {
   MSG_BLUE("Testing Profile1D: ");
 
-  MSG_("Creating the Profile1D: ");
+  MSG_(PAD(70) << "Creating the Profile1D: ");
   Profile1D p(100,0,100);
   p.fill(1,1,2);
   MSG_GREEN("PASS");
 
-  MSG_("Scaling the height: ");
+  MSG_(PAD(70) << "Scaling the height: ");
   p.scaleW(3);
   if (p.sumW() != 6 || p.sumW2() != 36) {
     MSG_RED("FAIL");
@@ -20,7 +20,7 @@
   }
   MSG_GREEN("PASS");
 
-  MSG_("Resetting the profile: ");
+  MSG_(PAD(70) << "Resetting the profile: ");
   p.reset();
   if (p.sumW() != 0 || p.sumW2() != 0){
     MSG_RED("FAIL");
@@ -28,7 +28,7 @@
   }
   MSG_GREEN("PASS");
 
-  MSG_("Merging the bins: ");
+  MSG_(PAD(70) << "Merging the bins: ");
   p.mergeBins(0,10);
   if (p.bin(0).xMin() != 0 || p.bin(0).xMax() != 11){
     MSG_RED("FAIL");
@@ -40,7 +40,7 @@
   }
   MSG_GREEN("PASS");
 
-  MSG_("Testing rebinning: ");
+  MSG_(PAD(70) << "Testing rebinning: ");
   p.rebin(2);
   for (size_t i = 1; i < p.bins().size() - 1; ++i){
     if (2 != p.bin(i).width()){
@@ -54,7 +54,7 @@
   }
   MSG_GREEN("PASS");
 
-  MSG_("Trying to add a bin (first method): ");
+  MSG_(PAD(70) << "Trying to add a bin (first method): ");
   p.addBin(110, 120);
   if (p.numBins() != 46){
     MSG_RED("FAIL");
@@ -62,7 +62,7 @@
   }
   MSG_GREEN("PASS");
 
-  MSG_("Trying to add a bin (second method): ");
+  MSG_(PAD(70) << "Trying to add a bin (second method): ");
   vector<double> test;
   test.push_back(120); test.push_back( 140); test.push_back(145);
   p.addBins(test);
@@ -72,7 +72,7 @@
   }
   MSG_GREEN("PASS");
 
-  // MSG("Trying to add a bin (third method): ");
+  // MSG_(PAD(70) << "Trying to add a bin (third method): ");
   // vector<pair<double,double> > test2;
   // test2.push_back(make_pair(180,190));
   // p.addBins(test2);


More information about the yoda-svn mailing list