Add tests for Chromosome and Generation.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 8 Apr 2015 06:32:05 +0000 (08:32 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Wed, 8 Apr 2015 06:32:05 +0000 (08:32 +0200)
configure.ac
tests/Makefile.am
tests/chromosome/Makefile.am [new file with mode: 0644]
tests/chromosome/copy.cpp [new file with mode: 0644]
tests/chromosome/create.cpp [new file with mode: 0644]
tests/gene/Makefile.am
tests/generation/Makefile.am [new file with mode: 0644]
tests/generation/copy.cpp [new file with mode: 0644]
tests/generation/create.cpp [new file with mode: 0644]

index 25a8fedc43ae60d9e071281cdf6189143565d541..28bc56ea307c0666b3362b336202eaaa6171353c 100644 (file)
@@ -8,6 +8,8 @@ AC_CONFIG_FILES([
     Makefile
     tests/Makefile
     tests/gene/Makefile
+    tests/chromosome/Makefile
+    tests/generation/Makefile
 ])
 
 AC_OUTPUT
index 417b2110ade0189d6cc0ed3e345eebe2e383267a..b869300203e8ee10d297492d50bb964acaff4822 100644 (file)
@@ -1,4 +1,7 @@
-SUBDIRS = gene
+SUBDIRS = \
+       gene \
+       chromosome \
+       generation
 
 clean-local:
        rm -f *.log
\ No newline at end of file
diff --git a/tests/chromosome/Makefile.am b/tests/chromosome/Makefile.am
new file mode 100644 (file)
index 0000000..51f78d9
--- /dev/null
@@ -0,0 +1,16 @@
+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/chromosome/copy.cpp b/tests/chromosome/copy.cpp
new file mode 100644 (file)
index 0000000..d5a34ba
--- /dev/null
@@ -0,0 +1,42 @@
+#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;
+}
+
diff --git a/tests/chromosome/create.cpp b/tests/chromosome/create.cpp
new file mode 100644 (file)
index 0000000..37e97fd
--- /dev/null
@@ -0,0 +1,39 @@
+#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;
+}
+
index 85ec6e854f72d074c814274c608e5dd27b701a36..cfb4b12245246858733d8ac33135c4fb0c611696 100644 (file)
@@ -10,7 +10,7 @@ TESTS = \
     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
diff --git a/tests/generation/Makefile.am b/tests/generation/Makefile.am
new file mode 100644 (file)
index 0000000..429c927
--- /dev/null
@@ -0,0 +1,16 @@
+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/generation/copy.cpp b/tests/generation/copy.cpp
new file mode 100644 (file)
index 0000000..9543483
--- /dev/null
@@ -0,0 +1,50 @@
+#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;
+}
+
diff --git a/tests/generation/create.cpp b/tests/generation/create.cpp
new file mode 100644 (file)
index 0000000..730713d
--- /dev/null
@@ -0,0 +1,48 @@
+#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;
+}
+