Library: draft tests to document the new features

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«
This commit is contained in:
Fischlurch 2024-03-11 17:44:19 +01:00
parent 0e88dec28a
commit 6e8c07ccd6
7 changed files with 492 additions and 0 deletions

67
src/lib/test/temp-dir.hpp Normal file
View file

@ -0,0 +1,67 @@
/*
TEMP-DIR.hpp - automatic allocation of a temporary working directory
Copyright (C) Lumiera.org
2024, Hermann Vosseler <Ichthyostega@web.de>
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 <unordered_map>
//#include <iostream>
//#include <vector>
//#include <map>
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*/

View file

@ -20,6 +20,11 @@ return: 0
END
PLANNED "Temporary working directory" TempDir_test <<END
return: 0
END
TEST "Helper for event registration and verification" EventLog_test <<END
err-lit: __Log_condition_violated__
err-lit: FAILED to match("γ")

12
tests/16calculation.tests Normal file
View file

@ -0,0 +1,12 @@
TESTING "Library Test Suite: calculation" ./test-suite --group=calculation
PLANNED "Data Table with CSV storage" DataCSV_test <<END
return: 0
END
PLANNED "Statistic and Regression" Statistic_test << END
return: 0
END

View file

@ -0,0 +1,121 @@
/*
DataCSV(Test) - verify data table with CSV storage support
Copyright (C) Lumiera.org
2009, Hermann Vosseler <Ichthyostega@web.de>
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 <functional>
//#include <string>
//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 T>
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

View file

@ -0,0 +1,122 @@
/*
Statistic(Test) - validate simple statistic calculations
Copyright (C) Lumiera.org
2009, Hermann Vosseler <Ichthyostega@web.de>
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 <functional>
//#include <string>
//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 T>
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

View file

@ -0,0 +1,112 @@
/*
TempDir(Test) - verify automated temporary working directory
Copyright (C) Lumiera.org
2009, Hermann Vosseler <Ichthyostega@web.de>
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 <boost/algorithm/string.hpp>
#include <fstream>
//#include <functional>
//#include <string>
//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

View file

@ -57094,6 +57094,9 @@
<node CREATED="1536015509308" ID="ID_1011220828" MODIFIED="1557498707236" TEXT="geschickt verpacken"/>
<node CREATED="1536015513076" ID="ID_849722427" MODIFIED="1557498707236" TEXT="den Regex-Include opaque halten"/>
<node CREATED="1536015525154" ID="ID_1039059758" MODIFIED="1557498707236" TEXT="soll mal in util.hpp"/>
<node BACKGROUND_COLOR="#d2beaf" COLOR="#5c4d6e" CREATED="1710170380632" ID="ID_1053362389" MODIFIED="1710170414556" TEXT="aus Yoshimi-test &#x27f9; lib/stat/regex.hpp">
<icon BUILTIN="hourglass"/>
</node>
</node>
<node COLOR="#338800" CREATED="1685583627381" FOLDED="true" ID="ID_1193075176" MODIFIED="1685631528263" TEXT="iterierbare Integer-Sequenz">
<linktarget COLOR="#64a3bc" DESTINATION="ID_1193075176" ENDARROW="Default" ENDINCLINATION="-872;80;" ID="Arrow_ID_49892110" SOURCE="ID_1477861363" STARTARROW="None" STARTINCLINATION="-1069;-69;"/>
@ -57233,6 +57236,13 @@
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710170202711" ID="ID_828243870" MODIFIED="1710170421762" TEXT="TempDir : ein tempor&#xe4;res Arbeitsverzeichnis f&#xfc;r Tests">
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710170260096" ID="ID_1777987925" MODIFIED="1710170459123" TEXT="Verhalten definiert per TempDir_test">
<arrowlink COLOR="#ad7a88" DESTINATION="ID_992572632" ENDARROW="Default" ENDINCLINATION="-1582;-265;" ID="Arrow_ID_891079113" STARTARROW="None" STARTINCLINATION="1511;114;"/>
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
</node>
<node CREATED="1695850005910" ID="ID_673181142" MODIFIED="1695851233120" TEXT="&#xbb;Either&#xab; : lib::Result">
@ -111833,9 +111843,52 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<icon BUILTIN="flag-yellow"/>
</node>
</node>
<node BACKGROUND_COLOR="#ccb59b" COLOR="#6e2a38" CREATED="1710169538785" HGAP="-5" ID="ID_1706582137" MODIFIED="1710169562437" VSHIFT="16">
<richcontent TYPE="NODE"><html>
<head/>
<body>
<p>
die Funktionalit&#228;t selber <b>steht nicht zur Debatte</b>
</p>
</body>
</html></richcontent>
<font ITALIC="true" NAME="SansSerif" SIZE="14"/>
<icon BUILTIN="yes"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710085571918" ID="ID_1847964804" MODIFIED="1710085586443" TEXT="per Unit-Test dokumentieren">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1710167567738" ID="ID_116953186" MODIFIED="1710168515030" TEXT="neue Test-Gruppe: 16calculation.tests">
<node CREATED="1710167587540" ID="ID_1196727143" MODIFIED="1710167645967" TEXT="group=calculation"/>
<node CREATED="1710167598409" ID="ID_498080750" MODIFIED="1710167615767" TEXT="Mathematik, aber auch Farbr&#xe4;ume und Signalverarbeitung"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710170186234" ID="ID_992572632" MODIFIED="1710170471944" TEXT="TempDir_test">
<linktarget COLOR="#ad7a88" DESTINATION="ID_992572632" ENDARROW="Default" ENDINCLINATION="-1582;-265;" ID="Arrow_ID_891079113" SOURCE="ID_1777987925" STARTARROW="None" STARTINCLINATION="1511;114;"/>
<icon BUILTIN="flag-yellow"/>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1710170516550" ID="ID_1675475629" MODIFIED="1710175170639" TEXT="simpleUsage">
<icon BUILTIN="pencil"/>
<node CREATED="1710170549626" ID="ID_1134291003" MODIFIED="1710170554749" TEXT="RAII-Objekt erstellen"/>
<node CREATED="1710170555509" ID="ID_1842541319" MODIFIED="1710170574082" TEXT="Datei dorhin platzieren"/>
<node CREATED="1710170575118" ID="ID_819300234" MODIFIED="1710170577186" TEXT="reinschreiben"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710170579669" ID="ID_16645191" MODIFIED="1710170590652" TEXT="verify_Lifecycle">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1710170593004" ID="ID_1544820358" MODIFIED="1710170600981" TEXT="mehrere RAII-Objekte"/>
<node CREATED="1710170615896" ID="ID_1289416435" MODIFIED="1710170620870" TEXT="haben verschiedene Pfade"/>
<node CREATED="1710170623288" ID="ID_212131047" MODIFIED="1710170629899" TEXT="sind nachher weg"/>
<node CREATED="1710170641389" ID="ID_39926847" MODIFIED="1710170645400" TEXT="auch bei Exception"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710163662386" ID="ID_694159551" MODIFIED="1710170478456" TEXT="DataCSV_test">
<icon BUILTIN="flag-yellow"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710163672834" ID="ID_778295326" MODIFIED="1710170479867" TEXT="Statistic_test">
<icon BUILTIN="flag-yellow"/>
<node CREATED="1710168517151" MODIFIED="1710168517151" TEXT="demonstrate_DataSpan();"/>
<node CREATED="1710168517152" MODIFIED="1710168517152" TEXT="check_baseStatistics();"/>
<node CREATED="1710168517152" MODIFIED="1710168517152" TEXT="check_wightedLinearRegression();"/>
<node CREATED="1710168517153" MODIFIED="1710168517153" TEXT="check_TimeSeriesLinearRegression();"/>
</node>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1710079820663" ID="ID_346209836" MODIFIED="1710079838390" TEXT="ein gnuplot-Skript generieren">