Add BitGenerator tests. Restructure tests.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 8 Apr 2015 17:49:44 +0000 (19:49 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 8 Apr 2015 17:49:44 +0000 (19:49 +0200)
configure.ac
src/generator/bitGenerator.h [moved from src/generator/bit.h with 92% similarity]
src/main.cpp
tests/Makefile.am
tests/chromosome/Makefile.am [deleted file]
tests/gene/Makefile.am [deleted file]
tests/generation/Makefile.am [deleted file]
tests/generator/bitGenerator/breed.cpp [new file with mode: 0644]

index 6777448535a79e4e4a20c0dc7461c78e0f155dc4..e8b6f95152f0996a21f72ff30ac879b00b474fa1 100644 (file)
@@ -7,9 +7,6 @@ AC_PROG_CXX
 AC_CONFIG_FILES([
     Makefile
     tests/Makefile
-    tests/gene/Makefile
-    tests/chromosome/Makefile
-    tests/generation/Makefile
 ])
 
 AC_OUTPUT
similarity index 92%
rename from src/generator/bit.h
rename to src/generator/bitGenerator.h
index 7bd50073a412fbee8c6b145e96f271301b727a64..8e92521a608e7c553f1689600dd0d622f1828232 100644 (file)
@@ -18,7 +18,7 @@ namespace genetic {
          * Generator for generating entire Generation of Chromosomes (individuals)
          */
         template < typename _Chromosome >
-        class Bit : public Generator<_Chromosome> {
+        class BitGenerator : public Generator<_Chromosome> {
         public:
             /**
              * Type representing Chromosome Gene
@@ -52,7 +52,7 @@ namespace genetic {
              * @param generationSize Indicates size of the generation
              * @param chromosomeSize Indicates size of the chromosome
              */
-            Bit(unsigned int generationSize, unsigned int chromosomeSize)
+            BitGenerator(unsigned int generationSize, unsigned int chromosomeSize)
                 : Generator<_Chromosome>(generationSize, chromosomeSize) {
             }
         };
index 51beb23d76b9edccb679b3159d005c7cb61f5c11..336285a52c5175239d4b074d1500f429710e7cab 100644 (file)
@@ -6,7 +6,7 @@
 #include "gene.h"
 #include "chromosome.h"
 #include "generation.h"
-#include "generator/bit.h"
+#include "generator/bitGenerator.h"
 
 #include "selection/rouletteSelection.h"
 #include "selection/linearRankSelection.h"
@@ -30,7 +30,7 @@ int main() {
     typedef Crossover<_Chromosome> _Crossover;
     typedef Mutation<_Chromosome> _Mutation;
 
-    typedef generator::Bit<_Chromosome> _Generator;
+    typedef generator::BitGenerator<_Chromosome> _Generator;
     typedef Algorithm<_Chromosome, _Selection, _Crossover, _Mutation, _Fitness> _Algorithm;
     typedef GenerationLimit<_Chromosome> _Condition;
 
index b869300203e8ee10d297492d50bb964acaff4822..6dcf89a1a729fc9075cc72b8048320477c974515 100644 (file)
@@ -1,7 +1,30 @@
-SUBDIRS = \
-       gene \
-       chromosome \
-       generation
+AUTOMAKE_OPTIONS = subdir-objects
+
+TESTS = \
+       gene_create.test \
+       gene_copy.test \
+       chromosome_create.test\
+       chromosome_copy.test \
+       generation_create.test\
+       generation_copy.test \
+       generator_bitGeneratorBreed.test
+
+noinst_PROGRAMS = $(TESTS)
+
+AM_CPPFLAGS   = -O2 -I$(top_srcdir)/src
+
+gene_create_test_SOURCES  = gene/create.cpp
+gene_copy_test_SOURCES  = gene/copy.cpp
+
+chromosome_create_test_SOURCES  = chromosome/create.cpp
+chromosome_copy_test_SOURCES  = chromosome/copy.cpp
+
+generation_create_test_SOURCES  = generation/create.cpp
+generation_copy_test_SOURCES  = generation/copy.cpp
+
+generator_bitGeneratorBreed_test_SOURCES  = generator/bitGenerator/breed.cpp
 
 clean-local:
-       rm -f *.log
\ No newline at end of file
+       rm -f *.log
+
+all-local:
\ No newline at end of file
diff --git a/tests/chromosome/Makefile.am b/tests/chromosome/Makefile.am
deleted file mode 100644 (file)
index 51f78d9..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-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
diff --git a/tests/gene/Makefile.am b/tests/gene/Makefile.am
deleted file mode 100644 (file)
index cfb4b12..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-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-gene:    create.test copy.test
-
-clean-local:
-       rm -f *.test
\ No newline at end of file
diff --git a/tests/generation/Makefile.am b/tests/generation/Makefile.am
deleted file mode 100644 (file)
index 429c927..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-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
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;
+}
+