From 91a0dc691efff2a35f9d2089be485117b426a04c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Wed, 8 Apr 2015 01:32:02 +0200 Subject: [PATCH] Add tests. --- Makefile.am | 2 ++ autogen.sh | 1 + configure.ac | 6 +++++- tests/Makefile.am | 4 ++++ tests/gene/Makefile.am | 16 ++++++++++++++++ tests/gene/copy.cpp | 24 ++++++++++++++++++++++++ tests/gene/create.cpp | 21 +++++++++++++++++++++ tests/gene/test1.cpp | 18 ------------------ 8 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 tests/Makefile.am create mode 100644 tests/gene/Makefile.am create mode 100644 tests/gene/copy.cpp create mode 100644 tests/gene/create.cpp delete mode 100644 tests/gene/test1.cpp diff --git a/Makefile.am b/Makefile.am index c543161..77706d6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,8 @@ CLEANFILES = \ %~ \ doxyfile.stamp +SUBDIRS = . tests + bin_PROGRAMS = bin/genetic dist_noinst_SCRIPTS = autogen.sh diff --git a/autogen.sh b/autogen.sh index fcd4df5..bfb874e 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,3 +1,4 @@ #! /bin/sh autoreconf --force --install +automake --add-missing \ No newline at end of file diff --git a/configure.ac b/configure.ac index 04d60cc..25a8fed 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,11 @@ AC_PREREQ([2.59]) AM_INIT_AUTOMAKE([1.10 -Wall]) AC_CONFIG_HEADERS([config.h]) AC_PROG_CXX -AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([ + Makefile + tests/Makefile + tests/gene/Makefile +]) AC_OUTPUT diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..417b211 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,4 @@ +SUBDIRS = gene + +clean-local: + rm -f *.log \ No newline at end of file diff --git a/tests/gene/Makefile.am b/tests/gene/Makefile.am new file mode 100644 index 0000000..85ec6e8 --- /dev/null +++ b/tests/gene/Makefile.am @@ -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-gene: create.test copy.test all + +clean-local: + rm -f *.test \ No newline at end of file diff --git a/tests/gene/copy.cpp b/tests/gene/copy.cpp new file mode 100644 index 0000000..554fa12 --- /dev/null +++ b/tests/gene/copy.cpp @@ -0,0 +1,24 @@ +#include + +#include "gene.h" + +using namespace std; +using namespace genetic; + +int main() { + typedef Gene _Gene; + + _Gene gene(1); + _Gene gene2(20); + + gene = gene2; + + if (gene.get() != 20) { + cout << "Gene does not copied value\n"; + } + + cout << "Gene copied value from second gene\n"; + + return 0; +} + diff --git a/tests/gene/create.cpp b/tests/gene/create.cpp new file mode 100644 index 0000000..9bc970e --- /dev/null +++ b/tests/gene/create.cpp @@ -0,0 +1,21 @@ +#include + +#include "gene.h" + +using namespace std; +using namespace genetic; + +int main() { + typedef Gene _Gene; + + _Gene gene(1); + + if (gene.get() != 1) { + cout << "Gene does not contained initial value\n"; + return 1; + } + + cout << "Gene contained initial value\n"; + return 0; +} + diff --git a/tests/gene/test1.cpp b/tests/gene/test1.cpp deleted file mode 100644 index eed1e94..0000000 --- a/tests/gene/test1.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#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; -} - -- 2.30.2