/trunk/sources/src/Test/TstAlleleSet.cpp
# · C++ · 158 lines · 106 code · 26 blank · 26 comment · 13 complexity · 4bef78df3669e952ef4516f3c4df80b9 MD5 · raw file
- // TstAlleleSet.cpp : Defines the entry point for the console application.
- //
- // Copyright (C) 1998 DIDIERJEAN <fabrice@coredmp.net>
- //
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation; either version 2 of the License, or
- // (at your option) any later version.
- //
- // This program 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 Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program; if not, write to the Free Software
- // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- // $Date: 2008-01-12 21:15:05 +0100 (Sat, 12 Jan 2008) $
- // $Id: TstAlleleSet.cpp 129 2008-01-12 20:15:05Z coredmp $
- // $Revision: 129 $
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include <iostream>
- #include <iomanip>
- #include <math.h>
- #include <AgCSP/Error.h>
- #include <AgCSP/AlleleSet.h>
- //#ifdef _DEBUGAGCSP
- ostream *debug = &cout;
- time_t tm=5;
- int dl=4;
- //#endif
- int main(int argc, char* argv[])
- {
- cerr << "================================================================================\n";
- long i,j,ret = 0,idx;
- try {
- cerr << "Test de la classe AlleleSet\n";
- cerr << "Essais de toutes les fonctions\n";
- cerr << "Constructeur par default :";
- AlleleSet al;
- cerr << " OK\n";
- cerr << "AddAllele() :";
- for(i=0;i<10;i++)
- al.addAllele(i);
- cerr << " OK\n";
- //cerr << "getAllele() :";
- // const vector<long> &v=al.getAlleles();
- //cerr << " OK\n";
- cerr << "getName() :" << al.getName() << " OK\n";
- cerr << "newVal() :" << al.newVal() << " OK\n";
- cerr << "setName() :";
- al.setName("GAG");
- cerr << " OK\n";
- cerr << "subAllele() :";
- al.subAllele(5);
- cerr << " OK\n";
-
- // binf est = 0 ou < 0 pas >0
- cerr << "Verification semantique\n";
- AlleleSet al2("Test");
- cerr <<"Repartition Alleatoire :";
- const long nbtirage=500000,taille=100,binf=0;
- const double ecart=0.1;
- double pec;
- for(i=binf; i<binf+taille; i++)
- al2.addAllele(i);
- vector<double> tirage(taille);
-
- for(i=0;i<taille;i++)
- tirage[i]=0;
-
- for(i=0;i<nbtirage;i++) {
- j = al2.newVal()-binf;
- tirage[j]+=1;
- }
- i=0;
- idx=-1;
- double max=0;
- while(i<taille) {
- pec = fabs(tirage[i]-nbtirage/taille)/((double)nbtirage/(double)taille);
- if(pec>max) {
- max = pec;
- idx=i;
- }
-
- i++;
- }
- cerr << " ecart max :"<<max<<" ("<<idx<<") ";
-
- if(max>ecart)
- throw Error("TstAlleleSet","Ecart Statistique trop important");
-
- cerr <<" OK\n";
-
- cerr << "Essais retrait valeur inconnu :";
- try {
- al2.subAllele(binf+taille+1);
- } catch(const Error &err) {
- if(err.getCode() != Error::ALLELE_INTROUVABLE) {
- cerr << "Pas la bonne erreur\n";
- throw;
- }
- }
- cerr << " OK\n";
-
- cerr << "Test d'allocation dynamique :";
- const int nbinst = 1000;
- AlleleSet *al3[nbinst],al4[nbinst],*al5[nbinst];
- for(i=0; i<nbinst;i++) {
- for(j=0;j<taille;j++)
- al4[i].addAllele(j);
- al3[i] = new AlleleSet;
- al5[i] = new AlleleSet(al4[i]);
- }
- for(i=0;i<nbinst;i++)
- *al3[i] = al4[i];
-
- for(i=0;i<nbinst;i++) {
- delete al3[i];
- delete al5[i];
- }
- cerr << " OK\n";
-
- } catch(const Error &err) {
- cerr << "\n";
- ret = err.getCode();
- err.aff(cerr);
- cerr << "\n";
- } catch(...) {
- cerr << "Ca merde\n";
- ret = 1;
- }
-
-
- #ifdef _WIN32
- cerr << "FIN appuyer sur une touche :";
- string stp;
- cin >> stp;
- #endif
- cerr << "________________________________________________________________________________\n";
- return ret;
- }