Ignore:
Timestamp:
Apr 21, 2005, 11:47:05 PM (18 years ago)
Author:
Peter
Message:

major revision of style of tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/test_merge.cc

    r107 r285  
    11// $Id$
    22
    3 #include <iostream>
     3#include "Merge.h"
     4
    45#include <fstream>
    56#include <string>
    67
    7 #include "FileIO.h"
    8 #include "Merge.h"
    9 
    10 // class for command line options
    11 class Parameter {
    12 public:
    13   Parameter(const Parameter&);  // not implemented
    14   Parameter(const int argc,const char *argv[]);
    15 
    16   inline const std::string& data(void) const { return data_file_; }
    17   inline const std::string& error(void) const { return error_file_; }
    18   inline const std::string& annots(void) const { return annots_file_; }
    19 
    20 private:
    21   void analyse(void);
    22   void defaults(void);
    23 
    24   std::string data_file_;
    25   std::string error_file_;
    26   std::string annots_file_;
    27 
    28 };
    29 
    30 Parameter::Parameter(const int argc,const char *argv[])
    31 {
    32   using namespace std;
    33   // check if help requested
    34   for (int i=1; i<argc; i++)
    35     if (string(argv[i])==string("-help") || string(argv[i])==string("-h")) {
    36       cout << "Please write some help information\n";
    37       exit(0);      // always exit after printing help
    38     }
    39 
    40   defaults();
    41 
    42   for (int i=1; i<argc; i++) {
    43     bool ok=false;
    44     string myargv(argv[i]);
    45     if (myargv==string("-data"))
    46       if ((i+1)<argc) {
    47         data_file_=argv[++i];
    48         ok=true;
    49       }
    50     if (myargv==string("-error"))
    51       if ((i+1)<argc) {
    52         error_file_=argv[++i];
    53         ok=true;
    54       }
    55     if (myargv==string("-annots"))
    56       if ((i+1)<argc) {
    57         annots_file_=argv[++i];
    58         ok=true;
    59       }
    60 
    61     if (!ok)
    62       std::cerr << "# Parameter::Parameter     Invalid option: "
    63                 << argv[i] << '\n';
    64   }
    65 
    66   analyse();
    67 }
    68 
    69 void Parameter::analyse(void)
    70 {
    71   using namespace theplu::cpptools;
    72   bool ok=true;
    73   if (FileIO().access_rights(data(),"r")) {
    74     std::cerr << "Cannot access data file " << data() << std::endl;
    75     ok=false;
    76   }
    77   if (FileIO().access_rights(error(),"r")) {
    78     std::cerr << "Cannot access error file " << error() << std::endl;
    79     ok=false;
    80   }if (FileIO().access_rights(annots(),"r")) {
    81     std::cerr << "Cannot access annotation file " << annots() << std::endl;
    82     ok=false;
    83   }
    84   if (!ok)
    85     std::exit(-1);
    86 }
    87 
    88 void Parameter::defaults(void)
    89 {
    90   data_file_="data/merge_matrix.data";
    91   error_file_="data/merge_error.data";
    92   annots_file_="data/merge_annots.data";
    93 }
    948
    959int main(const int argc,const char* argv[])
    9610{
    97   Parameter option(argc,argv);
    98   std::ifstream data_stream(option.data().c_str());
    99   std::ifstream error_stream(option.error().c_str());
    100   std::ifstream annots_stream(option.annots().c_str());
     11  std::ifstream data_stream("data/merge_matrix.data");
     12  std::ifstream error_stream("data/merge_error.data");
     13  std::ifstream annots_stream("data/merge_annots.data");
    10114  theplu::cpptools::Merge merge(data_stream,error_stream,annots_stream);
    102   std::cout << "data matrix" << std::endl;
    103   std::cout << merge.data_matrix() << std::endl;
    104   std::cout << "error matrix" << std::endl;
    105   std::cout << merge.error_matrix() << std::endl;
    10615  merge.do_something();
    107   std::cout << "new data matrix" << std::endl;
    108   std::cout << merge.data_matrix() << std::endl;
    109   std::cout << "new error matrix" << std::endl;
    110   std::cout << merge.error_matrix() << std::endl;
    11116  return 0; // normal exit
    11217}
Note: See TracChangeset for help on using the changeset viewer.