/* -*- mode: C++ -*- */
//////////////////////////////////////////////////////////////////////////////
// FILE   : test.tol
// PURPOSE: Package MatQuery test
//////////////////////////////////////////////////////////////////////////////

Text email_ = "vdebuen@tol-project.org"; 
Text link_ = ""; 
Text summary_ = "checking matrix row selection of unknown values";

//Write here the initial test TOL code if needed
Real numErr0 = Copy(NError);
Real numWar0 = Copy(NWarning);

#Require MatQuery;
//#Embed "../../../_embed_all.tol";

Real t1 = Copy(Time);
Real rndSeed = 0;
Real m = 300;

VMatrix unk.match = LE(Rand(m,1,0,1),Rand(m,1,1,1)*.20);
VMatrix M = IfVMat(unk.match, Rand(m,1,1,1)*?, Rand(m,1,-10,10));

VMatrix unk.match_ = MatQuery::MatchRowsWithValue(M,?);
Real ok.1 = VMatMax(Abs(unk.match-unk.match))==0;

Set sel.known = MatQuery::SelectMatch(Not(unk.match_));

VMatrix extract.known = SubRow(M, sel.known);

Real ok.2 = VMatSum(IsUnknown(extract.known))==0;
Real ok.3 = VRows(extract.known)==m-VMatSum(unk.match);


Real numErr1 = Copy(NError);
Real numWar1 = Copy(NWarning);

Set partialResults_ = [[numErr0, numErr1, 
                        ok.1, ok.2, ok.3]];

//This is a messure of the success of the test 
Real quality_ = And(numErr1 == numErr0, 
                    numWar1 <= numWar0, 
                    ok.1, ok.2, ok.3);

//Return the results 
Set resultStr_ = @strTestStatus(summary_, link_, quality_,
                  "Partial results = "<<partialResults_,
                  "NO DBServerType", "NO DBServerHost", "NO DBAlias",
                  email_);
WriteLn(""<<resultStr_);
resultStr_;

/* */

