Invocation: implement and test "mixing" of dummy-frames

Bugfix: should use the full bit-range for randomised data in `TestFrame`
Bugfix: prevent division by zero for approximate floatingpoint equality

...and use the new zip()-itertor to simplify the loops
This commit is contained in:
Fischlurch 2024-11-27 15:31:50 +01:00
parent 99c4663719
commit 3bdb5b9dd6
6 changed files with 105 additions and 41 deletions

View file

@ -66,7 +66,7 @@ namespace test{
roughEQ (F val, N target, F limit =ROUGH_PRECISION)
{
REQUIRE (0 < limit);
return abs (val/target - F(1)) < limit;
return abs (val - target) < limit * abs(target);
} //////////////////////////////////////////////////////////////////////////TICKET #1360 looks like this problem was solved several times

View file

@ -20,11 +20,12 @@
#include "lib/hash-combine.hpp"
#include "steam/engine/test-rand-ontology.hpp" ///////////TODO
#include "lib/test/diagnostic-output.hpp"/////////////////TODO
#include "lib/iter-zip.hpp"
#include "lib/random.hpp"
//#include "lib/util.hpp"
//using std::string;
using lib::zip;
namespace steam {
@ -69,6 +70,7 @@ namespace test {
processing_generateFrame();
processing_generateMultichan();
processing_manipulateFrame();
processing_combineFrames();
}
@ -104,7 +106,7 @@ namespace test {
for (uint i=0; i<channels; ++i)
CHECK (not buffs[i]->isSane());
generateMultichan (channels, buffs[0], frameNr, flavour);
generateMultichan (buffs[0], channels, frameNr, flavour);
for (uint i=0; i<channels; ++i)
{
CHECK (buffs[i]->isSane());
@ -124,7 +126,7 @@ namespace test {
iBuff.buildData(frameNr,flavour);
oBuff.buildData(frameNr,flavour);
CHECK (iBuff->isPristine());
CHECK (iBuff->isPristine());
CHECK (oBuff->isPristine());
uint64_t param = defaultGen.u64();
manipulateFrame (oBuff, iBuff, param);
@ -132,14 +134,15 @@ namespace test {
CHECK (not oBuff->isPristine());
CHECK ( iBuff->isPristine());
for (uint i=0; i<oBuff->data64().size(); ++i)
for (auto [iDat,oDat] : zip (iBuff->data64()
,oBuff->data64()))
{
CHECK (oDat != iDat);
uint64_t feed = param;
uint64_t data = iBuff->data64()[i];
lib::hash::combine (feed, data);
CHECK (data == iBuff->data64()[i]);
CHECK (feed != iBuff->data64()[i]);
CHECK (feed == oBuff->data64()[i]);
lib::hash::combine (feed, iDat);
CHECK (feed != param);
CHECK (feed != iDat);
CHECK (feed == oDat);
}
// can also process in-place
manipulateFrame (iBuff, iBuff, param);
@ -147,6 +150,41 @@ namespace test {
CHECK ( iBuff->isValid());
CHECK (*iBuff == *oBuff); // second invocation exactly reproduced data from first invocation
}
/** @test function to mix two test data frames
*/
void
processing_combineFrames()
{
size_t frameNr = defaultGen.u64();
uint flavour = defaultGen.u64();
Buffer i1Buff, i2Buff, oBuff;
i1Buff.buildData(frameNr,flavour+0);
i2Buff.buildData(frameNr,flavour+1);
oBuff.buildData();
CHECK (i1Buff->isPristine());
CHECK (i2Buff->isPristine());
CHECK (oBuff->isPristine());
double mix = defaultGen.uni();
combineFrames (oBuff, i1Buff, i2Buff, mix);
CHECK ( oBuff->isValid());
CHECK (not oBuff->isPristine());
CHECK ( i1Buff->isPristine());
CHECK ( i2Buff->isPristine());
for (auto [oDat,i1Dat,i2Dat] : zip (oBuff->data()
,i1Buff->data()
,i2Buff->data()))
CHECK (oDat == std::lround((1-mix)*i1Dat + mix*i2Dat));
// can also process in-place
combineFrames (i1Buff, i1Buff, i2Buff, mix);
CHECK (not i1Buff->isPristine());
CHECK ( i1Buff->isValid());
CHECK (*i1Buff == *oBuff); // second invocation exactly reproduced data from first invocation
}
};

View file

@ -25,9 +25,12 @@
#include "steam/engine/test-rand-ontology.hpp"
#include "lib/hash-combine.hpp"
#include "lib/iter-zip.hpp"
//#include <vector>
#include <cmath>
using std::lround;
using lib::zip;
namespace steam {
@ -67,7 +70,7 @@ namespace test {
* which will be offset commonly by adding the \a flavour parameter.
*/
void
generateMultichan (uint chanCnt, TestFrame* buffArry, size_t frameNr, uint flavour)
generateMultichan (TestFrame* buffArry, uint chanCnt, size_t frameNr, uint flavour)
{
REQUIRE (buffArry);
for (uint i=0; i<chanCnt; ++i)
@ -87,8 +90,8 @@ namespace test {
REQUIRE (in);
REQUIRE (out);
auto calculate = [](uint64_t chain, uint64_t val){ lib::hash::combine(chain,val); return chain; };
for (size_t i=0; i < in->data64().size(); ++i)
out->data64()[i] = calculate(param, in->data64()[i]);
for (auto& [res,src] : zip (out->data64(), in->data64()))
res = calculate(param, src);
out->markChecksum();
}
@ -101,13 +104,15 @@ namespace test {
* each result byte is the linear interpolation between the corresponding inputs.
*/
void
combineFrames (TestFrame* out, TestFrame const* srcA, TestFrame const* srcB, int mix)
combineFrames (TestFrame* out, TestFrame const* srcA, TestFrame const* srcB, double mix)
{
REQUIRE (srcA);
REQUIRE (srcB);
REQUIRE (out);
for (size_t i=0; i < srcA->data().size(); ++i)
out->data()[i] = char((1-mix) * srcA->data()[i] + mix * srcB->data()[i]);
for (auto& [res,inA,inB] : zip (out->data()
,srcA->data()
,srcB->data()))
res = lround((1-mix)*inA + mix*inB);
out->markChecksum();
}

View file

@ -35,16 +35,16 @@ namespace test {
using std::string;
/** produce sequences of frames with (reproducible) random data */
void generateFrame (TestFrame* buff, size_t frameNr, uint flavour);
void generateFrame (TestFrame* buff, size_t frameNr =0, uint flavour =0);
/** produce planar multi channel output of random data frames */
void generateMultichan (uint chanCnt, TestFrame* buffArry, size_t frameNr, uint flavour);
void generateMultichan (TestFrame* buffArry, uint chanCnt, size_t frameNr =0, uint flavour =0);
/** »process« random frame date by hash-chaining with a parameter */
void manipulateFrame (TestFrame* out, TestFrame const* in, uint64_t param);
/** mix two random data frames by a parameter-controlled proportion */
void combineFrames (TestFrame* out, TestFrame const* srcA, TestFrame const* srcB, int mix);
void combineFrames (TestFrame* out, TestFrame const* srcA, TestFrame const* srcB, double mix);

View file

@ -314,8 +314,7 @@ namespace test {
bool
TestFrame::contentEquals (TestFrame const& o) const
{
return header_ == o.header_
and data() == o.data();
return data() == o.data();
}
@ -331,8 +330,8 @@ namespace test {
TestFrame::buildData()
{
auto gen = buildDataGenFrom (accessHeader().distinction);
for (char& dat : data())
dat = char(gen.i(CHAR_MAX));
for (uint64_t& dat : data64())
dat = gen.u64();
markChecksum();
}
@ -343,8 +342,8 @@ namespace test {
TestFrame::matchDistinction() const
{
auto gen = buildDataGenFrom (accessHeader().distinction);
for (char const& dat : data())
if (dat != char(gen.i(CHAR_MAX)))
for (uint64_t const& dat : data64())
if (dat != gen.u64())
return false;
return true;
}

View file

@ -52490,6 +52490,9 @@
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1689250675659" ID="ID_328217249" MODIFIED="1689250679379" TEXT="Varianten?">
<icon BUILTIN="help"/>
</node>
<node COLOR="#435e98" CREATED="1732662964542" ID="ID_750332784" MODIFIED="1732662983731" TEXT="IterStateWrapper : packt eine State-Core iterierbar ein">
<icon BUILTIN="yes"/>
</node>
<node COLOR="#435e98" CREATED="1689249180884" ID="ID_1169599821" MODIFIED="1689252396083" TEXT="IterableDecorator : minimalistischer Core-Adapter">
<linktarget COLOR="#4f65c2" DESTINATION="ID_1169599821" ENDARROW="Default" ENDINCLINATION="-74;-108;" ID="Arrow_ID_680083681" SOURCE="ID_552745986" STARTARROW="None" STARTINCLINATION="-68;10;"/>
<linktarget COLOR="#4b58db" DESTINATION="ID_1169599821" ENDARROW="Default" ENDINCLINATION="-1279;68;" ID="Arrow_ID_1606137974" SOURCE="ID_537950394" STARTARROW="None" STARTINCLINATION="-2178;95;"/>
@ -52531,6 +52534,22 @@
<icon BUILTIN="idea"/>
</node>
</node>
<node COLOR="#435e98" CREATED="1732663057961" ID="ID_789157501" MODIFIED="1732663219795" TEXT="kann nun auch R&#xfc;ckgabe-Werte handhaben">
<icon BUILTIN="idea"/>
<node CREATED="1732663227537" ID="ID_639164239" MODIFIED="1732663289174" TEXT="iter::CoreYield&lt;C&gt;">
<icon BUILTIN="forward"/>
<node CREATED="1732663240953" ID="ID_1622364735" MODIFIED="1732663275785" TEXT="kann Typ&amp; oder Typ (value) sein">
<icon BUILTIN="idea"/>
</node>
<node COLOR="#5b280f" CREATED="1732663252003" ID="ID_1437880320" MODIFIED="1732663270883" TEXT="im Value-Fall wird operator-&gt; nicht unterst&#xfc;tzt">
<icon BUILTIN="yes"/>
</node>
</node>
<node CREATED="1732663115409" ID="ID_1558751662" MODIFIED="1732663157193" TEXT="Erweiterung f&#xfc;r IterExplorer::Expander und f&#xfc;r iter-zip">
<linktarget COLOR="#4bb4e2" DESTINATION="ID_1558751662" ENDARROW="Default" ENDINCLINATION="411;23;" ID="Arrow_ID_1082389405" SOURCE="ID_73007932" STARTARROW="None" STARTINCLINATION="-3;-253;"/>
</node>
<node CREATED="1732663177454" ID="ID_1504939437" LINK="#ID_1774747868" MODIFIED="1732663196246" TEXT="Dokumentation: IterCoreAdapter_test"/>
</node>
</node>
<node CREATED="1535890810111" ID="ID_677938944" MODIFIED="1557498707236" TEXT="IterSource">
<node CREATED="1535890823613" ID="ID_1227701237" MODIFIED="1557498707236" TEXT="Lumiera Iterator als Abstraktion"/>
@ -52545,9 +52564,10 @@
</node>
</node>
</node>
<node COLOR="#338800" CREATED="1732154493179" ID="ID_1329557703" MODIFIED="1732659010836" TEXT="iter-zip">
<node COLOR="#338800" CREATED="1732154493179" FOLDED="true" ID="ID_1329557703" MODIFIED="1732663211618" TEXT="iter-zip">
<icon BUILTIN="button_ok"/>
<node CREATED="1732154503106" ID="ID_852276140" MODIFIED="1732154521492" TEXT="N Iteratoren in Tupel zusammenf&#xfc;hren">
<node CREATED="1732154503106" ID="ID_852276140" MODIFIED="1732662891264" TEXT="N Iteratoren in Tupel zusammenf&#xfc;hren">
<icon BUILTIN="info"/>
<node CREATED="1732154525721" ID="ID_161696884" MODIFIED="1732154540166" TEXT="zum Verbinden mehrerer Datenquellen"/>
<node CREATED="1732154540893" ID="ID_1426555488" MODIFIED="1732154577823" TEXT="es gilt die kleinst-m&#xf6;gliche Gesamtsequenz">
<richcontent TYPE="NOTE"><html>
@ -52559,7 +52579,7 @@
</body>
</html></richcontent>
</node>
<node CREATED="1732154580080" ID="ID_336146444" MODIFIED="1732154642685" TEXT="wichtige Variante: zip-with-index">
<node CREATED="1732154580080" ID="ID_336146444" MODIFIED="1732662882164" TEXT="wichtige Variante: izip &#x2259; zip-with-index">
<richcontent TYPE="NOTE"><html>
<head/>
<body>
@ -52894,7 +52914,7 @@
</node>
</node>
</node>
<node COLOR="#338800" CREATED="1732235208972" ID="ID_1764687143" MODIFIED="1732636372831" TEXT="nun in Library-Code extrahieren">
<node COLOR="#338800" CREATED="1732235208972" FOLDED="true" ID="ID_1764687143" MODIFIED="1732636372831" TEXT="nun in Library-Code extrahieren">
<icon BUILTIN="button_ok"/>
<node COLOR="#435e98" CREATED="1732299521810" ID="ID_185815307" MODIFIED="1732313502381" TEXT="schlank halten: es gen&#xfc;gt die ProductCore">
<icon BUILTIN="yes"/>
@ -53092,7 +53112,7 @@
</node>
</node>
</node>
<node COLOR="#338800" CREATED="1732235272468" ID="ID_1892180908" MODIFIED="1732637867027" TEXT="gr&#xfc;ndlich testen">
<node COLOR="#338800" CREATED="1732235272468" FOLDED="true" ID="ID_1892180908" MODIFIED="1732637867027" TEXT="gr&#xfc;ndlich testen">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1732308670586" ID="ID_351914878" MODIFIED="1732308678431" TEXT="einfaches Demo-Beispiel">
<icon BUILTIN="button_ok"/>
@ -53259,7 +53279,7 @@
</node>
</node>
</node>
<node COLOR="#338800" CREATED="1732235523602" ID="ID_1940842867" MODIFIED="1732577239677" TEXT="Durchgriff auf Child-Expander im Quell-Iterator">
<node COLOR="#338800" CREATED="1732235523602" FOLDED="true" ID="ID_1940842867" MODIFIED="1732577239677" TEXT="Durchgriff auf Child-Expander im Quell-Iterator">
<icon BUILTIN="button_ok"/>
<node COLOR="#338800" CREATED="1732404127247" ID="ID_1051749303" MODIFIED="1732489015844" TEXT="setzt Anpassungen an den Adaptern voraus">
<arrowlink COLOR="#599ced" DESTINATION="ID_87985222" ENDARROW="Default" ENDINCLINATION="180;171;" ID="Arrow_ID_1403487927" STARTARROW="None" STARTINCLINATION="425;-32;"/>
@ -53274,7 +53294,7 @@
<node COLOR="#338800" CREATED="1732489334100" ID="ID_744918133" MODIFIED="1732489351281" TEXT="das eigentliche Weiterleiten der Aufrufe ist trivial einfach zu implementieren">
<icon BUILTIN="button_ok"/>
</node>
<node COLOR="#435e98" CREATED="1732489352034" FOLDED="true" ID="ID_1389747588" MODIFIED="1732636282025" TEXT="Testen ist m&#xfc;hsam....">
<node COLOR="#435e98" CREATED="1732489352034" ID="ID_1389747588" MODIFIED="1732636282025" TEXT="Testen ist m&#xfc;hsam....">
<node BACKGROUND_COLOR="#c8c0b6" CREATED="1732499374948" ID="ID_1694141748" MODIFIED="1732576950165" TEXT="geht schon los mit....">
<node COLOR="#435e98" CREATED="1732499382404" ID="ID_298429500" MODIFIED="1732636249571" TEXT="...dem Umstand, da&#xdf; der Expander nicht auf Value-Result funktioniert">
<icon BUILTIN="broken-line"/>
@ -53288,6 +53308,7 @@
</node>
</node>
<node COLOR="#435e98" CREATED="1732499748626" ID="ID_73007932" MODIFIED="1732658339211" TEXT="nochmal untersuchen: k&#xf6;nnen wir Value-Ergebnisse aus der Pipeline unterst&#xfc;tzen?">
<arrowlink COLOR="#4bb4e2" DESTINATION="ID_1558751662" ENDARROW="Default" ENDINCLINATION="411;23;" ID="Arrow_ID_1082389405" STARTARROW="None" STARTINCLINATION="-3;-253;"/>
<linktarget COLOR="#4e6fd7" DESTINATION="ID_73007932" ENDARROW="Default" ENDINCLINATION="-1571;53;" ID="Arrow_ID_1348614829" SOURCE="ID_1087558825" STARTARROW="None" STARTINCLINATION="-292;13;"/>
<icon BUILTIN="help"/>
<node COLOR="#435e98" CREATED="1732499767002" FOLDED="true" ID="ID_1245640841" MODIFIED="1732636236208" TEXT="Problem-1 : operator-&gt; kann nicht unterst&#xfc;tzt werden">
@ -54845,8 +54866,7 @@
in value-type-binding.hpp
</p>
</body>
</html>
</richcontent>
</html></richcontent>
<icon BUILTIN="idea"/>
<node CREATED="1732658531445" ID="ID_89938606" MODIFIED="1732658541039" TEXT="baut auf std::common_type auf"/>
<node CREATED="1732658543427" ID="ID_720852404" MODIFIED="1732658555157" TEXT="handhabt aber Referenz und Const-Eigenschaft explizit"/>
@ -93379,6 +93399,8 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</p>
</body>
</html></richcontent>
<node CREATED="1732717089403" ID="ID_1509612203" MODIFIED="1732717099901" TEXT="mit Einschr&#xe4;nkung : rechne in 64bit"/>
<node CREATED="1732717102481" ID="ID_1246427992" MODIFIED="1732717115729" TEXT="also Zugriff &#xfc;ber data64()-Array"/>
</node>
<node CREATED="1732145995543" ID="ID_209219518" MODIFIED="1732146006347" TEXT="Verkn&#xfc;pfung mehrerer Eingabpuffer">
<node COLOR="#435e98" CREATED="1732146009058" ID="ID_422352708" MODIFIED="1732146038271" TEXT="linearer Mix von zwei Eingabepuffern"/>
@ -93627,12 +93649,12 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node CREATED="1730827701591" ID="ID_1382558170" MODIFIED="1730827720498" TEXT="mu&#xdf; nun beginnen, die Test-Processing-Funktionen zu organisieren">
<icon BUILTIN="smily_bad"/>
</node>
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1730827749568" ID="ID_607130868" MODIFIED="1732121192105" TEXT="die Basis-Funktionen als free-functions realisieren">
<node COLOR="#338800" CREATED="1730827749568" ID="ID_607130868" MODIFIED="1732716870574" TEXT="die Basis-Funktionen als free-functions realisieren">
<arrowlink COLOR="#556273" DESTINATION="ID_391399838" ENDARROW="Default" ENDINCLINATION="-384;24;" ID="Arrow_ID_290133862" STARTARROW="None" STARTINCLINATION="257;-992;"/>
<icon BUILTIN="pencil"/>
<node CREATED="1730828045224" ID="ID_874340553" MODIFIED="1730828060299" TEXT="generateFrame"/>
<node CREATED="1730828224345" ID="ID_1955731193" MODIFIED="1730828238872" TEXT="generateMultichan"/>
<node CREATED="1730828061609" ID="ID_234342122" MODIFIED="1730828068429" TEXT="manipulateFrame">
<icon BUILTIN="button_ok"/>
<node COLOR="#435e98" CREATED="1730828045224" ID="ID_874340553" MODIFIED="1732716867458" TEXT="generateFrame"/>
<node COLOR="#435e98" CREATED="1730828224345" ID="ID_1955731193" MODIFIED="1732716867458" TEXT="generateMultichan"/>
<node COLOR="#435e98" CREATED="1730828061609" ID="ID_234342122" MODIFIED="1732716867457" TEXT="manipulateFrame">
<node COLOR="#338800" CREATED="1730835481751" ID="ID_936086670" MODIFIED="1730835554245" TEXT="brauche nun direkten Zugang zu den payload-Daten">
<arrowlink COLOR="#77313e" DESTINATION="ID_442258905" ENDARROW="Default" ENDINCLINATION="381;-48;" ID="Arrow_ID_1047269362" STARTARROW="None" STARTINCLINATION="-36;80;"/>
<icon BUILTIN="yes"/>
@ -93641,7 +93663,7 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<icon BUILTIN="button_ok"/>
</node>
</node>
<node CREATED="1730828077684" ID="ID_1553228902" MODIFIED="1730828099886" TEXT="combineFrames"/>
<node COLOR="#435e98" CREATED="1730828077684" ID="ID_1553228902" MODIFIED="1732716867457" TEXT="combineFrames"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1730827961401" ID="ID_927640003" MODIFIED="1730827975594" TEXT="die Test-Ontology als Singleton zug&#xe4;nglich machen">
<icon BUILTIN="flag-yellow"/>