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