1 /*
  2  * =====================================================================================
  3  *
  4  *       Filename:  test_del.cpp
  5  *
  6  *    Description:  Testing Double Deletes
  7  *
  8  *        Version:  1.0
  9  *        Created:  04/02/2011 05:12:24 PM
 10  *       Revision:  none
 11  *       Compiler:  gcc
 12  *
 13  *         Author:  YOUR NAME Ruben Safir,
 14  *        Company:  NYLXS
 15  *
 16  * =====================================================================================
 17  */
 18
 19
 20
 21 #ifndef  LINKLIST
 22 #define LINKLIST
 23 #include        "linklist.h"
 24 #include       "stats.h"
 25 #endif     /* -----  not LINKLIST  ----- */
 26
 27 #include        <iostream>
 28 #include        <fstream>
 29 #include        <climits>
 30 #include        <stdlib.h>
 31 #include        <iomanip>
 32
 33 chainlist::List<int>* creating_int_list();
 34 void find_all_examples(chainlist::List<int>*&, int);
 35
 36
 37
 38
 39
 40 chainlist::List<stats::Distribution<int> > * tally;  //a list of distribution talleys in global space
 41 chainlist::List< chainlist::List< stats::Distribution<int> >* > * tallies;  //a list of distribution talleys in global space
 42
 43
 44
 45 int main ( int argc, char *argv[] ){
 46
 47    tally = new chainlist::List<stats::Distribution<int> >;
 48    tallies = new chainlist::List< chainlist::List< stats::Distribution<int> > *>;
 49
 50    srand(12345);
 51    unsigned int i;
 52    chainlist::List<chainlist::List<int> * > a;
 53    for( i=0; i < 100; ++i){
 54       std::cout << "CREATING LIST for ARRAY -------------------------------\n";
 55       a[i] = creating_int_list();
 56       a[i]->sort(*(a[i]));
 57       std::cout << "Sorted List" << std::endl;
 58 //      a[i]->display();
 59       std::cout << std::endl;
 60    }
 61    a.sort(a);
 62
 63
 64    for( i=0; i < 100; ++i){
 65       std::cout << "NEW SEARCH in index " << i << "-------------------------------\n";
 66       stats::take_tally<int>(a[i], tally);
 67    }
 68    std::cout << "The standard mean is ==> " << stats::mean_list(tally) << std::endl;
 69    std::cout << "The standard deviation is ==> " << stats::stddev(tally) << std::endl;
 70 //   tally->display();
 71    delete tally;
 72
 73    std::cout << "tally deleted - next loop " << std::endl;
 74
 75
 76
 77 //test of new stddev overload that takes a list of lists of distributions
 78
 79    for( i=0; i < 100; ++i){
 80       std::cout << "index " << i << "-------------------------------\n";
 81       tally = new chainlist::List<stats::Distribution<int> >;
 82       stats::take_tally<int>(a[i], tally );
 83       std::cout << "Creating Tally " << std::endl;
 84       tallies->insert(tally);
 85       std::cout << "inserted population figures for index " << i << "-------------------------------\n";
 86 //      delete tally;
 87
 88 //visual inspection of population data to make sure the resiults work
 89 //      std::cout << "visual inspection of population data to make sure the results work" << std::endl;
 90 //      for(j=0;j < 100; j++){
 91 //       std::cout << "NEW SEARCH in value " << j << "-------------------------------\n";
 92 //       find_all_examples(a[i], j);
 93 //      }
 94    }
 95    std::cout << "The standard mean for picking 7 is ==> " << stats::mean_list(tallies, 7 ) << std::endl;;
 96    std::cout << "The standard deviation for 7 in our test is ==> " << stats::stddev(tallies, 7) << std::endl;
 97   
 98
 99    for( i=0; i < 100; ++i){
100       delete a[i];
101    }
102    return EXIT_SUCCESS;
103 }                               /* ----------  end of function main  ---------- */
104
105
106 chainlist::List<int> * creating_int_list(){
107    // chainlist::List<int>  set = new chainlist::List<int>;
108    chainlist::List<int> * set = new chainlist::List<int>;
109    int ran;
110    for(int i = 0; i < 100; ++i){
111       ran=rand();
112       set->insert(ran % 100);
113    }
114    set->display();
115    return set;
116 }
117
118 void find_all_examples ( chainlist::List<int>* & glob, int search_value )
119 {
120    std::cout << "Searching for " <<  search_value << " in list \n" ;
121    glob->display();
122    glob->find_value(search_value);
123    chainlist::Node<int> * found = glob->cursor();
124    if(found){
125       std::cout << "Found first value ==> '" << *found->value() << "' at node =='" << glob->cursor() << std::endl;
126       found = glob->find_next_value(search_value, found);
127       while( found ){
128          std::cout << "Found next value ==> '" << *(found->value()) << "' at node =='" << glob->cursor() << std::endl;
129          found = glob->find_next_value(search_value, found);
130       }
131    }
132
133
134    return ;
135 }              
136