Makefile
tests/Makefile
tests/gene/Makefile
+ tests/chromosome/Makefile
+ tests/generation/Makefile
])
AC_OUTPUT
-SUBDIRS = gene
+SUBDIRS = \
+ gene \
+ chromosome \
+ generation
clean-local:
rm -f *.log
\ No newline at end of file
--- /dev/null
+noinst_PROGRAMS = create.test copy.test
+
+create_test_SOURCES = create.cpp
+create_test_CPPFLAGS = -I$(top_srcdir)/src
+
+copy_test_SOURCES = copy.cpp
+copy_test_CPPFLAGS = -I$(top_srcdir)/src
+
+TESTS = \
+ create.test \
+ copy.test
+
+check-chromosome: create.test copy.test
+
+clean-local:
+ rm -f *.test
\ No newline at end of file
--- /dev/null
+#include <iostream>
+#include <vector>
+
+#include "gene.h"
+#include "chromosome.h"
+
+using namespace std;
+using namespace genetic;
+
+int main() {
+ typedef Gene<int> _Gene;
+ typedef Chromosome<_Gene> _Chromosome;
+
+ const unsigned int chromosomeSize = 20;
+
+ std::vector<_Gene> data;
+
+ for (unsigned int i = 0; i < chromosomeSize; i++) {
+ data.push_back(_Gene(i));
+ }
+
+ _Chromosome chromosome(data);
+ _Chromosome chromosome2;
+
+ chromosome2 = chromosome;
+
+ if (chromosome2.size() != chromosomeSize) {
+ cout << "Chromosome contained incorrect size after copying\n";
+ return 1;
+ }
+
+ for (unsigned int i = 0; i < chromosome2.size(); i++) {
+ if (chromosome2[i].get() != i) {
+ cout << "Chromosome contained bad data after copying\n";
+ return 1;
+ }
+ }
+
+ cout << "Chromosome copies data correctly\n";
+ return 0;
+}
+
--- /dev/null
+#include <iostream>
+#include <vector>
+
+#include "gene.h"
+#include "chromosome.h"
+
+using namespace std;
+using namespace genetic;
+
+int main() {
+ typedef Gene<int> _Gene;
+ typedef Chromosome<_Gene> _Chromosome;
+
+ const unsigned int chromosomeSize = 20;
+
+ std::vector<_Gene> data;
+
+ for (unsigned int i = 0; i < chromosomeSize; i++) {
+ data.push_back(_Gene(i));
+ }
+
+ _Chromosome chromosome(data);
+
+ if (chromosome.size() != chromosomeSize) {
+ cout << "Chromosome contained incorrect size after creation\n";
+ return 1;
+ }
+
+ for (unsigned int i = 0; i < chromosome.size(); i++) {
+ if (chromosome[i].get() != i) {
+ cout << "Chromosome contained bad data after creation\n";
+ return 1;
+ }
+ }
+
+ cout << "Chromosome is created correctly\n";
+ return 0;
+}
+
create.test \
copy.test
-check-gene: create.test copy.test all
+check-gene: create.test copy.test
clean-local:
rm -f *.test
\ No newline at end of file
--- /dev/null
+noinst_PROGRAMS = create.test copy.test
+
+create_test_SOURCES = create.cpp
+create_test_CPPFLAGS = -I$(top_srcdir)/src
+
+copy_test_SOURCES = copy.cpp
+copy_test_CPPFLAGS = -I$(top_srcdir)/src
+
+TESTS = \
+ create.test \
+ copy.test
+
+check-generation: create.test copy.test
+
+clean-local:
+ rm -f *.test
\ No newline at end of file
--- /dev/null
+#include <iostream>
+#include <vector>
+
+#include "gene.h"
+#include "chromosome.h"
+#include "generation.h"
+
+using namespace std;
+using namespace genetic;
+
+int main() {
+ typedef Gene<int> _Gene;
+ typedef Chromosome<_Gene> _Chromosome;
+ typedef Generation<_Chromosome> _Generation;
+
+ const unsigned int chromosomeSize = 20;
+ const unsigned int generationSize = 100;
+
+ std::vector<_Gene> chromosomeData;
+ std::vector<_Chromosome> generationData;
+
+ for (unsigned int i = 0; i < generationSize; i++) {
+ for (unsigned int j = 0; j < chromosomeSize; j++) {
+ chromosomeData.push_back(_Gene(i*j));
+ }
+ generationData.push_back(_Chromosome(chromosomeData));
+ }
+
+ _Generation generation(generationData);
+
+ _Generation generation2 = generation;
+
+ if (generation2.size() != generation.size()) {
+ cout << "Generation contained incorrect size after copying\n";
+ return 1;
+ }
+
+ for (unsigned int i = 0; i < generation.size(); i++) {
+ for (unsigned int j = 0; j < generation[i].size(); j++) {
+ if (generation[i][j].get() != generationData[i][j].get()) {
+ cout << "Generation contained bad data after copying\n";
+ return 1;
+ }
+ }
+ }
+
+ cout << "Generation is created correctly\n";
+ return 0;
+}
+
--- /dev/null
+#include <iostream>
+#include <vector>
+
+#include "gene.h"
+#include "chromosome.h"
+#include "generation.h"
+
+using namespace std;
+using namespace genetic;
+
+int main() {
+ typedef Gene<int> _Gene;
+ typedef Chromosome<_Gene> _Chromosome;
+ typedef Generation<_Chromosome> _Generation;
+
+ const unsigned int chromosomeSize = 20;
+ const unsigned int generationSize = 100;
+
+ std::vector<_Gene> chromosomeData;
+ std::vector<_Chromosome> generationData;
+
+ for (unsigned int i = 0; i < generationSize; i++) {
+ for (unsigned int j = 0; j < chromosomeSize; j++) {
+ chromosomeData.push_back(_Gene(i*j));
+ }
+ generationData.push_back(_Chromosome(chromosomeData));
+ }
+
+ _Generation generation(generationData);
+
+ if (generation.size() != generationSize) {
+ cout << "Generation contained incorrect size after creation\n";
+ return 1;
+ }
+
+ for (unsigned int i = 0; i < generation.size(); i++) {
+ for (unsigned int j = 0; j < generation[i].size(); j++) {
+ if (generation[i][j].get() != generationData[i][j].get()) {
+ cout << "Generation contained bad data after creation\n";
+ return 1;
+ }
+ }
+ }
+
+ cout << "Generation is created correctly\n";
+ return 0;
+}
+