/trunk/sources/src/Test/TstAlleleSet.cpp

# · C++ · 158 lines · 106 code · 26 blank · 26 comment · 13 complexity · 4bef78df3669e952ef4516f3c4df80b9 MD5 · raw file

  1. // TstAlleleSet.cpp : Defines the entry point for the console application.
  2. //
  3. // Copyright (C) 1998 DIDIERJEAN <fabrice@coredmp.net>
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. // $Date: 2008-01-12 21:15:05 +0100 (Sat, 12 Jan 2008) $
  19. // $Id: TstAlleleSet.cpp 129 2008-01-12 20:15:05Z coredmp $
  20. // $Revision: 129 $
  21. #ifdef HAVE_CONFIG_H
  22. #include "config.h"
  23. #endif
  24. #include <iostream>
  25. #include <iomanip>
  26. #include <math.h>
  27. #include <AgCSP/Error.h>
  28. #include <AgCSP/AlleleSet.h>
  29. //#ifdef _DEBUGAGCSP
  30. ostream *debug = &cout;
  31. time_t tm=5;
  32. int dl=4;
  33. //#endif
  34. int main(int argc, char* argv[])
  35. {
  36. cerr << "================================================================================\n";
  37. long i,j,ret = 0,idx;
  38. try {
  39. cerr << "Test de la classe AlleleSet\n";
  40. cerr << "Essais de toutes les fonctions\n";
  41. cerr << "Constructeur par default :";
  42. AlleleSet al;
  43. cerr << " OK\n";
  44. cerr << "AddAllele() :";
  45. for(i=0;i<10;i++)
  46. al.addAllele(i);
  47. cerr << " OK\n";
  48. //cerr << "getAllele() :";
  49. // const vector<long> &v=al.getAlleles();
  50. //cerr << " OK\n";
  51. cerr << "getName() :" << al.getName() << " OK\n";
  52. cerr << "newVal() :" << al.newVal() << " OK\n";
  53. cerr << "setName() :";
  54. al.setName("GAG");
  55. cerr << " OK\n";
  56. cerr << "subAllele() :";
  57. al.subAllele(5);
  58. cerr << " OK\n";
  59. // binf est = 0 ou < 0 pas >0
  60. cerr << "Verification semantique\n";
  61. AlleleSet al2("Test");
  62. cerr <<"Repartition Alleatoire :";
  63. const long nbtirage=500000,taille=100,binf=0;
  64. const double ecart=0.1;
  65. double pec;
  66. for(i=binf; i<binf+taille; i++)
  67. al2.addAllele(i);
  68. vector<double> tirage(taille);
  69. for(i=0;i<taille;i++)
  70. tirage[i]=0;
  71. for(i=0;i<nbtirage;i++) {
  72. j = al2.newVal()-binf;
  73. tirage[j]+=1;
  74. }
  75. i=0;
  76. idx=-1;
  77. double max=0;
  78. while(i<taille) {
  79. pec = fabs(tirage[i]-nbtirage/taille)/((double)nbtirage/(double)taille);
  80. if(pec>max) {
  81. max = pec;
  82. idx=i;
  83. }
  84. i++;
  85. }
  86. cerr << " ecart max :"<<max<<" ("<<idx<<") ";
  87. if(max>ecart)
  88. throw Error("TstAlleleSet","Ecart Statistique trop important");
  89. cerr <<" OK\n";
  90. cerr << "Essais retrait valeur inconnu :";
  91. try {
  92. al2.subAllele(binf+taille+1);
  93. } catch(const Error &err) {
  94. if(err.getCode() != Error::ALLELE_INTROUVABLE) {
  95. cerr << "Pas la bonne erreur\n";
  96. throw;
  97. }
  98. }
  99. cerr << " OK\n";
  100. cerr << "Test d'allocation dynamique :";
  101. const int nbinst = 1000;
  102. AlleleSet *al3[nbinst],al4[nbinst],*al5[nbinst];
  103. for(i=0; i<nbinst;i++) {
  104. for(j=0;j<taille;j++)
  105. al4[i].addAllele(j);
  106. al3[i] = new AlleleSet;
  107. al5[i] = new AlleleSet(al4[i]);
  108. }
  109. for(i=0;i<nbinst;i++)
  110. *al3[i] = al4[i];
  111. for(i=0;i<nbinst;i++) {
  112. delete al3[i];
  113. delete al5[i];
  114. }
  115. cerr << " OK\n";
  116. } catch(const Error &err) {
  117. cerr << "\n";
  118. ret = err.getCode();
  119. err.aff(cerr);
  120. cerr << "\n";
  121. } catch(...) {
  122. cerr << "Ca merde\n";
  123. ret = 1;
  124. }
  125. #ifdef _WIN32
  126. cerr << "FIN appuyer sur une touche :";
  127. string stp;
  128. cin >> stp;
  129. #endif
  130. cerr << "________________________________________________________________________________\n";
  131. return ret;
  132. }