Add BitGenerator tests. Restructure tests.
[genetic.git] / tests / generator / bitGenerator / breed.cpp
diff --git a/tests/generator/bitGenerator/breed.cpp b/tests/generator/bitGenerator/breed.cpp
new file mode 100644 (file)
index 0000000..d6ec7c3
--- /dev/null
@@ -0,0 +1,45 @@
+#include <iostream>
+#include <vector>
+
+#include "gene.h"
+#include "chromosome.h"
+#include "generation.h"
+#include "generator/bitGenerator.h"
+
+using namespace std;
+using namespace genetic;
+
+int main() {
+    typedef Gene<int> _Gene;
+    typedef Chromosome<_Gene> _Chromosome;
+    typedef Generation<_Chromosome> _Generation;
+    typedef generator::BitGenerator<_Chromosome> _Generator;
+
+    const unsigned int chromosomeSize = 20;
+    const unsigned int generationSize = 100;
+
+    _Generator generator(generationSize, chromosomeSize);
+    _Generation generation = generator.breed();
+
+    if (generation.size() != generationSize) {
+        cout << "Generation contained incorrect size after breeding\n";
+        return 1;
+    }
+
+    for (unsigned int i = 0; i < generation.size(); i++) {
+        if (generation[i].size() != chromosomeSize) {
+            cout << "Chromosome contained bad size after breeding\n";
+            return 1;
+        }
+        for (unsigned int j = 0; j < generation[i].size(); j++) {
+            if ((generation[i][j].get() != 0) &&
+                (generation[i][j].get() != 1)) {
+                cout << "Chromosome breeded by BitGenerator does not have bit Genes\n";
+            }
+        }
+    }
+
+    cout << "BitGenerator breeded correctly\n";
+    return 0;
+}
+