Add tests for Chromosome and Generation.
[genetic.git] / tests / generation / copy.cpp
1 #include <iostream>
2 #include <vector>
3
4 #include "gene.h"
5 #include "chromosome.h"
6 #include "generation.h"
7
8 using namespace std;
9 using namespace genetic;
10
11 int main() {
12     typedef Gene<int> _Gene;
13     typedef Chromosome<_Gene> _Chromosome;
14     typedef Generation<_Chromosome> _Generation;
15
16     const unsigned int chromosomeSize = 20;
17     const unsigned int generationSize = 100;
18
19     std::vector<_Gene> chromosomeData;
20     std::vector<_Chromosome> generationData;
21
22     for (unsigned int i = 0; i < generationSize; i++) {
23         for (unsigned int j = 0; j < chromosomeSize; j++) {
24             chromosomeData.push_back(_Gene(i*j));
25         }
26         generationData.push_back(_Chromosome(chromosomeData));
27     }
28
29     _Generation generation(generationData);
30
31     _Generation generation2 = generation;
32
33     if (generation2.size() != generation.size()) {
34         cout << "Generation contained incorrect size after copying\n";
35         return 1;
36     }
37
38     for (unsigned int i = 0; i < generation.size(); i++) {
39         for (unsigned int j = 0; j < generation[i].size(); j++) {
40             if (generation[i][j].get() != generationData[i][j].get()) {
41                 cout << "Generation contained bad data after copying\n";
42                 return 1;
43             }
44         }
45     }
46
47     cout << "Generation is created correctly\n";
48     return 0;
49 }
50