[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master c695cd7 01/10: Add PETE vector tests
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master c695cd7 01/10: Add PETE vector tests |
Date: |
Mon, 1 Mar 2021 09:39:22 -0500 (EST) |
branch: master
commit c695cd72d96397bd120cc4ac620e54e0c128cc65
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add PETE vector tests
Brought
tools/pete-2.1.1/et_vector_test.cpp
into lmi's unit-test suite as
et_vector_0_test.cpp
with only minimal changes:
- updated copyrights to reflect all modification years
- added lmi unit-test boilerplate
- worked around useless-cast warnings
The '_0' differentiates this file from the original in tools/ ,
and allows for more types of tests to be added later--e.g., for
other expression-template libraries.
'timer.o' is linked because it'll probably be wanted eventually,
though it's not actually used now.
---
Makefile.am | 7 +++++
et_vector_0_test.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
objects.make | 6 ++++
3 files changed, 99 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index 1fafb1c..5757a0f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -107,6 +107,7 @@ TESTS = \
test_crc32 \
test_currency \
test_dbo_rules \
+ test_et_vector_0 \
test_expression_template_0 \
test_fenv_lmi \
test_file_command \
@@ -725,6 +726,12 @@ test_dbo_rules_SOURCES = \
timer.cpp
test_dbo_rules_CXXFLAGS = $(AM_CXXFLAGS)
+test_et_vector_0_SOURCES = \
+ $(common_test_objects) \
+ et_vector_0_test.cpp \
+ timer.cpp
+test_et_vector_0_CXXFLAGS = $(AM_CXXFLAGS)
+
test_expression_template_0_SOURCES = \
$(common_test_objects) \
expression_template_0_test.cpp \
diff --git a/et_vector_0_test.cpp b/et_vector_0_test.cpp
new file mode 100644
index 0000000..2405ef3
--- /dev/null
+++ b/et_vector_0_test.cpp
@@ -0,0 +1,86 @@
+// PETE with std::vector: unit test.
+//
+// Copyright (C) 2008, 2010, 2016, 2019, 2020, 2021 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// https://savannah.nongnu.org/projects/lmi
+// email: <gchicares@sbcglobal.net>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+#include "et_vector.hpp"
+
+#include "test_tools.hpp"
+
+#include <algorithm>
+#include <functional>
+#include <iostream>
+#include <iterator>
+
+template <typename T>
+void show_vector(std::vector<T> const& v)
+{
+ std::ostream_iterator<double> osi(std::cout, " ");
+ std::copy(v.begin(), v.end(), osi);
+ std::cout << std::endl;
+}
+
+int test_main(int, char*[])
+{
+ std::vector<double> v0;
+
+ v0.push_back(0.0);
+ v0.push_back(1.1);
+ v0.push_back(2.2);
+
+ v0 *= v0;
+
+ show_vector(v0);
+
+ // Test peteCast().
+ std::vector<int> v1(v0.size());
+ peteCast(int{}, v0);
+ assign(v1, peteCast(int{}, v0));
+ show_vector(v1);
+
+ // Test std::unary_function.
+ assign(v0, apply_unary(std::negate<double>(), v0));
+ show_vector(v0);
+
+ // Test std::binary_function.
+ assign(v0, apply_binary(std::multiplies<double>(), -1.0, v0));
+ show_vector(v0);
+ assign(v0, sqrt(v0));
+ show_vector(v0);
+ assign(v0, apply_binary(std::multiplies<double>(), v0, -1.0));
+ show_vector(v0);
+ assign(v0, apply_binary(std::multiplies<double>(), v0, v0));
+ show_vector(v0);
+ assign(v0, apply_binary(std::plus<double>(), v0, 100.0));
+ assign(v0, apply_binary(std::plus<double>(), 10000.0, v0));
+ show_vector(v0);
+
+ // Test Min() and Max().
+ std::vector<double> v2 = {1.2, 2.3, 3.4, 7.7};
+ std::vector<double> v3 = {1.9, 2.9, 3.9, 0.0};
+ std::vector<double> v4(v2.size());
+ assign(v4, Max(v2, v3));
+ show_vector(v4);
+ assign(v4, Min(v2, v3));
+ show_vector(v4);
+
+ std::cout << "Completed." << std::endl;
+
+ return 0;
+}
diff --git a/objects.make b/objects.make
index 2d7a799..dd982f2 100644
--- a/objects.make
+++ b/objects.make
@@ -421,6 +421,7 @@ unit_test_targets := \
crc32_test \
currency_test \
dbo_rules_test \
+ et_vector_0_test \
expression_template_0_test \
fenv_lmi_test \
file_command_test \
@@ -620,6 +621,11 @@ dbo_rules_test$(EXEEXT): \
mc_enum_types.o \
timer.o \
+et_vector_0_test$(EXEEXT): \
+ $(common_test_objects) \
+ et_vector_0_test.o \
+ timer.o \
+
expression_template_0_test$(EXEEXT): \
$(common_test_objects) \
expression_template_0_test.o \
- [lmi-commits] [lmi] master updated (e5b0ac2 -> 8ffc9d2), Greg Chicares, 2021/03/01
- [lmi-commits] [lmi] master e3c0e51 02/10: Improve PETE unit test, Greg Chicares, 2021/03/01
- [lmi-commits] [lmi] master 56f9792 06/10: Turn a member into a local variable, Greg Chicares, 2021/03/01
- [lmi-commits] [lmi] master c695cd7 01/10: Add PETE vector tests,
Greg Chicares <=
- [lmi-commits] [lmi] master 4d37390 03/10: Mention lmi's improved unit test, Greg Chicares, 2021/03/01
- [lmi-commits] [lmi] master 53186b7 05/10: Reorder independent blocks, Greg Chicares, 2021/03/01
- [lmi-commits] [lmi] master aab3295 07/10: Rename a local variable, Greg Chicares, 2021/03/01
- [lmi-commits] [lmi] master 3ef5a8e 08/10: Draw attention to an improvement deferred, Greg Chicares, 2021/03/01
- [lmi-commits] [lmi] master ecd20b1 04/10: Improve Max() and Min() implementations, Greg Chicares, 2021/03/01
- [lmi-commits] [lmi] master 8ffc9d2 10/10: Calculate 7702 'ig' more carefully, Greg Chicares, 2021/03/01
- [lmi-commits] [lmi] master f135b80 09/10: Assert correspondence between DB_GuarInt and DB_NaarDiscount, Greg Chicares, 2021/03/01