Created initial Gene and Chromosome. Added initial test for Gene.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 21 Mar 2015 18:09:37 +0000 (19:09 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sat, 21 Mar 2015 18:09:37 +0000 (19:09 +0100)
src/chromosome.h [new file with mode: 0644]
src/gene.h [new file with mode: 0644]
src/main.cpp
tests/gene/test1.cpp [new file with mode: 0644]

diff --git a/src/chromosome.h b/src/chromosome.h
new file mode 100644 (file)
index 0000000..b7e17df
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef __CHROMOSOME_H
+#define __CHROMOSOME_H
+
+#include <vector>
+
+#include <gene.h>
+
+using namespace std;
+
+namespace genetic {
+    template < typename _Gene >
+    class Chromosome {
+    protected:
+        vector<_Gene> genes;
+
+    public:
+        Chromosome(vector<_Gene> genes) {
+            this->genes = genes;
+        }
+
+        vector<_Gene> get() {
+            return this->genes;
+        }
+    };
+}
+
+#endif /* __CHROMOSOME_H */
\ No newline at end of file
diff --git a/src/gene.h b/src/gene.h
new file mode 100644 (file)
index 0000000..ddd8c71
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __GENE_H
+#define __GENE_H
+
+namespace genetic {
+
+    template < typename Type >
+    class Gene {
+    protected:
+        Type type;
+    public:
+        Gene(Type type) {
+            this->type = type;
+        }
+
+        Type get() {
+            return this->type;
+        }
+    };
+}
+
+#endif /* __GENE_H */
\ No newline at end of file
index c2bbf58abf71b13eb3dd8bbd22c853bef455f018..8d30c3b94171b1584aa6653076714349e3e2e3bb 100644 (file)
@@ -1,9 +1,28 @@
 #include <iostream>
+#include <vector>
+
+#include <cstdlib>
+
+#include "gene.h"
+#include "chromosome.h"
 
 using namespace std;
+using namespace genetic;
 
 int main() {
-    cout << "Hello World" << endl;
+    typedef Gene<int> _Gene;
+
+    time_t t;
+    srand((unsigned)time(&t));
+
+    vector<_Gene> genes;
+
+    for (int i = 0; i < 20; i++) {
+        _Gene gene(rand() % 255);
+        cout << "Generated gene: " << gene.get() << "\n";
+        genes.push_back(gene);
+    }
+    Chromosome<_Gene> chromosome(genes);
 
     return 0;
 }
diff --git a/tests/gene/test1.cpp b/tests/gene/test1.cpp
new file mode 100644 (file)
index 0000000..eed1e94
--- /dev/null
@@ -0,0 +1,18 @@
+#include <iostream>
+#include <cassert>
+
+#include "gene.h"
+#include "chromosome.h"
+
+using namespace std;
+using namespace genetic;
+
+int main() {
+    Gene<int> gene(1);
+
+    assert(gene.get() == 1);
+    cout << "Gene: " << gene.get() << " should be equal to: " << 1 << endl;
+
+    return 0;
+}
+