From: Rafał Długołęcki Date: Sat, 21 Mar 2015 18:09:37 +0000 (+0100) Subject: Created initial Gene and Chromosome. Added initial test for Gene. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=9ae7c021c43d6bdeae13bb2e8a4418e517679e01;p=genetic.git Created initial Gene and Chromosome. Added initial test for Gene. --- diff --git a/src/chromosome.h b/src/chromosome.h new file mode 100644 index 0000000..b7e17df --- /dev/null +++ b/src/chromosome.h @@ -0,0 +1,27 @@ +#ifndef __CHROMOSOME_H +#define __CHROMOSOME_H + +#include + +#include + +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 index 0000000..ddd8c71 --- /dev/null +++ b/src/gene.h @@ -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 diff --git a/src/main.cpp b/src/main.cpp index c2bbf58..8d30c3b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,28 @@ #include +#include + +#include + +#include "gene.h" +#include "chromosome.h" using namespace std; +using namespace genetic; int main() { - cout << "Hello World" << endl; + typedef Gene _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 index 0000000..eed1e94 --- /dev/null +++ b/tests/gene/test1.cpp @@ -0,0 +1,18 @@ +#include +#include + +#include "gene.h" +#include "chromosome.h" + +using namespace std; +using namespace genetic; + +int main() { + Gene gene(1); + + assert(gene.get() == 1); + cout << "Gene: " << gene.get() << " should be equal to: " << 1 << endl; + + return 0; +} +