From 6e8c07ccd6f35a10da87544833717e6f8e78ee41 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 11 Mar 2024 17:44:19 +0100 Subject: [PATCH] Library: draft tests to document the new features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Yesterday I decided to include some facilities I have written in 2022 for the Yoshimi-Testsuite. The intention is to use these as-is, and just to adapt them stylistically to the Lumiera code base. However — at least some basic documentation in the form of very basic unit-tests can be considered »acceptance criteria« --- src/lib/test/temp-dir.hpp | 67 ++++++++++++++ tests/00support.tests | 5 ++ tests/16calculation.tests | 12 +++ tests/library/stat/data-csv-test.cpp | 121 +++++++++++++++++++++++++ tests/library/stat/statistic-test.cpp | 122 ++++++++++++++++++++++++++ tests/library/test/temp-dir-test.cpp | 112 +++++++++++++++++++++++ wiki/thinkPad.ichthyo.mm | 53 +++++++++++ 7 files changed, 492 insertions(+) create mode 100644 src/lib/test/temp-dir.hpp create mode 100644 tests/16calculation.tests create mode 100644 tests/library/stat/data-csv-test.cpp create mode 100644 tests/library/stat/statistic-test.cpp create mode 100644 tests/library/test/temp-dir-test.cpp diff --git a/src/lib/test/temp-dir.hpp b/src/lib/test/temp-dir.hpp new file mode 100644 index 000000000..9bd2d3fac --- /dev/null +++ b/src/lib/test/temp-dir.hpp @@ -0,0 +1,67 @@ +/* + TEMP-DIR.hpp - automatic allocation of a temporary working directory + + Copyright (C) Lumiera.org + 2024, Hermann Vosseler + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + + +/** @file temp-dir.hpp + ** Manage a temporary directory for storage, with automated clean-up. + ** @see TempDir_test + */ + + +#ifndef LIB_TEST_TEMP_DIR_H +#define LIB_TEST_TEMP_DIR_H + + +#include "lib/error.hpp" +#include "lib/nocopy.hpp" +#include "lib/stat/file.hpp" +//#include +//#include +//#include +//#include + + +namespace lib { +namespace test{ + + /** + * A RAII style temporary directory. + */ + class TempDir + : util::MoveOnly + { + fs::path loc_; + + public: + TempDir() = default; + + + fs::path + makeFile() + { + UNIMPLEMENTED ("make temporary file"); + } + }; + + +}} // namespace lib::test +#endif /*LIB_TEST_TEMP_DIR_H*/ diff --git a/tests/00support.tests b/tests/00support.tests index c3bae974f..24da0687d 100644 --- a/tests/00support.tests +++ b/tests/00support.tests @@ -20,6 +20,11 @@ return: 0 END +PLANNED "Temporary working directory" TempDir_test < + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + +/** @file data-csv-test.cpp + ** unit test \ref DataCSV_test + */ + + +#include "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" +#include "lib/stat/data.hpp" +//#include "lib/time/timevalue.hpp" +//#include "lib/error.hpp" +//#include "lib/util-foreach.hpp" +#include "lib/format-cout.hpp" ///////////////////////TODO +#include "lib/test/diagnostic-output.hpp" ///////////////////////TODO + +//#include +//#include + +//using lumiera::Error; +//using lumiera::LUMIERA_ERROR_EXCEPTION; +//using lumiera::error::LUMIERA_ERROR_ASSERTION; +//using lib::time::TimeVar; +//using lib::time::Time; + +//using boost::algorithm::is_lower; +//using boost::algorithm::is_digit; +//using std::function; +//using std::string; + + +namespace lib { +namespace stat{ +namespace test{ + + template + class Wrmrmpft + { + T tt_; + }; + + struct Murpf { }; + + + /***********************************************************//** + * @test Document and verify a data table component to maintain + * measurement data series, backed by CSV storage. + * @see data.hpp + * @see csv.hpp + * @see Statistic_test + */ + class DataCSV_test : public Test + { + void + run (Arg) + { + checkGarbageStr(); + checkTypeDisplay(); + checkThrowChecker(); + checkLocalManipulation(); + } + + + /** @test prints "sizeof()" including some type name. */ + void + checkTypeDisplay () + { + } + + + + + void + checkGarbageStr() + { + } + + + /** @test check the VERIFY_ERROR macro, + * which ensures a given error is raised. + */ + void + checkThrowChecker() + { + } + + + /** @test check a local manipulations, + * which are undone when leaving the scope. + */ + void + checkLocalManipulation() + { + } + }; + + LAUNCHER (DataCSV_test, "unit calculation"); + + +}}} // namespace lib::stat::test + diff --git a/tests/library/stat/statistic-test.cpp b/tests/library/stat/statistic-test.cpp new file mode 100644 index 000000000..3cb6c14cd --- /dev/null +++ b/tests/library/stat/statistic-test.cpp @@ -0,0 +1,122 @@ +/* + Statistic(Test) - validate simple statistic calculations + + Copyright (C) Lumiera.org + 2009, Hermann Vosseler + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + +/** @file statistic-test.cpp + ** unit test \ref Statistic_test + */ + + +#include "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" +#include "lib/stat/statistic.hpp" +//#include "lib/time/timevalue.hpp" +//#include "lib/error.hpp" +//#include "lib/util-foreach.hpp" +#include "lib/format-cout.hpp" ///////////////////////TODO +#include "lib/test/diagnostic-output.hpp" ///////////////////////TODO + +//#include +//#include + +//using util::for_each; +//using lumiera::Error; +//using lumiera::LUMIERA_ERROR_EXCEPTION; +//using lumiera::error::LUMIERA_ERROR_ASSERTION; +//using lib::time::TimeVar; +//using lib::time::Time; + +//using boost::algorithm::is_lower; +//using boost::algorithm::is_digit; +//using std::function; +//using std::string; + + +namespace lib { +namespace stat{ +namespace test{ + + template + class Wrmrmpft + { + T tt_; + }; + + struct Murpf { }; + + + /**************************************************************//** + * @test verifies the proper working of statistic helper functions. + * - calculate mean and standard derivation + * - one-dimensional linear regression + * @see DataCSV_test.hpp + * @see statistic.hpp + */ + class Statistic_test : public Test + { + void + run (Arg) + { + demonstrate_DataSpan(); + check_baseStatistics(); + check_wightedLinearRegression(); + check_TimeSeriesLinearRegression(); + } + + + /** @test prints "sizeof()" including some type name. */ + void + check_baseStatistics () + { + } + + + + + void + demonstrate_DataSpan() + { + } + + + /** @test check the VERIFY_ERROR macro, + * which ensures a given error is raised. + */ + void + check_wightedLinearRegression() + { + } + + + /** @test check a local manipulations, + * which are undone when leaving the scope. + */ + void + check_TimeSeriesLinearRegression() + { + } + }; + + LAUNCHER (Statistic_test, "unit calculation"); + + +}}} // namespace lib::stat::test + diff --git a/tests/library/test/temp-dir-test.cpp b/tests/library/test/temp-dir-test.cpp new file mode 100644 index 000000000..310eb308e --- /dev/null +++ b/tests/library/test/temp-dir-test.cpp @@ -0,0 +1,112 @@ +/* + TempDir(Test) - verify automated temporary working directory + + Copyright (C) Lumiera.org + 2009, Hermann Vosseler + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + +/** @file temp-dir-test.cpp + ** unit test \ref TempDir_test + */ + + +#include "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" +#include "lib/test/temp-dir.hpp" +//#include "lib/time/timevalue.hpp" +//#include "lib/error.hpp" +//#include "lib/util-foreach.hpp" +#include "lib/format-cout.hpp" + +//#include +#include +//#include +//#include + +//using util::for_each; +//using lumiera::Error; +//using lumiera::LUMIERA_ERROR_EXCEPTION; +//using lumiera::error::LUMIERA_ERROR_ASSERTION; +//using lib::time::TimeVar; +//using lib::time::Time; + +//using boost::algorithm::is_lower; +//using boost::algorithm::is_digit; +//using std::function; +//using std::string; + + +namespace lib { +namespace test{ +namespace test{ + + + + + /***************************************************************//** + * @test validate proper working of a temporary working directory, + * with automatic name allocation and clean-up. + * @see temp-dir.hpp + * @see DataCSV_test usage example + */ + class TempDir_test : public Test + { + void + run (Arg) + { + simpleUsage(); + verify_Lifecycle(); + } + + + void + simpleUsage() + { + TempDir temp; + auto ff = temp.makeFile(); + CHECK (fs::exists (ff)); + CHECK (fs::is_empty (ff)); + + std::ofstream out{ff, std::ios_base::out}; + auto scree = randStr(55); + out << scree << endl; + out.close(); + + CHECK (fs::is_regular_file (ff)); + CHECK (not fs::is_empty (ff)); + + std::ifstream in{ff}; + string readBack; + in >> readBack; + CHECK (readBack == scree); + } + + + + /** @test prints "sizeof()" including some type name. */ + void + verify_Lifecycle () + { + } + }; + + LAUNCHER (TempDir_test, "unit common"); + + +}}} // namespace lib::test::test + diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 5d9bb4e83..ccd0fe350 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -57094,6 +57094,9 @@ + + + @@ -57233,6 +57236,13 @@ + + + + + + + @@ -111833,9 +111843,52 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + +

+ die Funktionalität selber steht nicht zur Debatte +

+ +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +