Skip to content

Commit

Permalink
Added ConstantBoundsLog, VariablesLog to validator testOverviewLogFile
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMirzayanov committed Jan 17, 2024
1 parent 269931f commit 36041fc
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 6 deletions.
78 changes: 72 additions & 6 deletions testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#define _TESTLIB_H_

/*
* Copyright (c) 2005-2023
* Copyright (c) 2005-2024
*/

#define VERSION "0.9.41"
#define VERSION "0.9.42-SNAPSHOT"

/*
* Mike Mirzayanov
Expand Down Expand Up @@ -63,6 +63,7 @@
*/

const char *latestFeatures[] = {
"Added ConstantBoundsLog, VariablesLog to validator testOverviewLogFile",
"Use setAppesModeEncoding to change xml encoding from windows-1251 to other",
"rnd.any/wany use distance/advance instead of -/+: now they support sets/multisets",
"Use syntax `int t = inf.readInt(1, 3, \"~t\");` to skip the lower bound check. Tildes can be used on either side or both: ~t, t~, ~t~",
Expand Down Expand Up @@ -2447,6 +2448,7 @@ class Validator {
std::map<std::string, ConstantBounds> _constantBoundsByVariableName;
std::set<std::string> _features;
std::set<std::string> _hitFeatures;
std::set<std::string> _variables;

bool isVariableNameBoundsAnalyzable(const std::string &variableName) {
for (size_t i = 0; i < variableName.length(); i++)
Expand Down Expand Up @@ -2551,11 +2553,28 @@ class Validator {
}
}

void addVariable(const std::string &variableName) {
if (isVariableNameBoundsAnalyzable(variableName)
&& _variables.size() < VALIDATOR_MAX_VARIABLE_COUNT) {
std::string preparedVariableName = prepVariableName(variableName);
_variables.insert(preparedVariableName);
}
}

std::string getVariablesLog() {
std::string result;
for (const std::string &variableName: _variables)
result += "variable \"" + variableName + "\"\n";
return result;
}

template<typename T>
void adjustConstantBounds(const std::string &variableName, T lower, T upper) {
if (_constantBoundsByVariableName.size() < VALIDATOR_MAX_VARIABLE_COUNT) {
_constantBoundsByVariableName[variableName].lowerBound.adjust(lower);
_constantBoundsByVariableName[variableName].upperBound.adjust(upper);
if (isVariableNameBoundsAnalyzable(variableName)
&& _constantBoundsByVariableName.size() < VALIDATOR_MAX_VARIABLE_COUNT) {
std::string preparedVariableName = prepVariableName(variableName);
_constantBoundsByVariableName[preparedVariableName].lowerBound.adjust(lower);
_constantBoundsByVariableName[preparedVariableName].upperBound.adjust(upper);
}
}

Expand Down Expand Up @@ -2624,7 +2643,11 @@ class Validator {
if (NULL == f)
__testlib_fail("Validator::writeTestOverviewLog: can't write test overview log to (" + fileName + ")");
}
fprintf(f, "%s%s%s", getBoundsHitLog().c_str(), getFeaturesLog().c_str(), getConstantBoundsLog().c_str());
fprintf(f, "%s%s%s%s",
getBoundsHitLog().c_str(),
getFeaturesLog().c_str(),
getConstantBoundsLog().c_str(),
getVariablesLog().c_str());
std::fflush(f);
if (!standard_file)
if (std::fclose(f))
Expand Down Expand Up @@ -3453,12 +3476,16 @@ std::string InStream::readWord(const pattern &p, const std::string &variableName
"\"").c_str());
}
}
if (strict && !variableName.empty())
validator.addVariable(variableName);
return _tmpReadToken;
}

std::vector<std::string>
InStream::readWords(int size, const pattern &p, const std::string &variablesName, int indexBase) {
__testlib_readMany(readWords, readWord(p, variablesName), std::string, true);
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::vector<std::string> InStream::readWords(int size, int indexBase) {
Expand All @@ -3473,6 +3500,8 @@ std::vector<std::string>
InStream::readWords(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) {
pattern p(ptrn);
__testlib_readMany(readWords, readWord(p, variablesName), std::string, true);
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::string InStream::readToken(const pattern &p, const std::string &variableName) {
Expand All @@ -3482,6 +3511,8 @@ std::string InStream::readToken(const pattern &p, const std::string &variableNam
std::vector<std::string>
InStream::readTokens(int size, const pattern &p, const std::string &variablesName, int indexBase) {
__testlib_readMany(readTokens, readToken(p, variablesName), std::string, true);
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::vector<std::string> InStream::readTokens(int size, int indexBase) {
Expand All @@ -3496,6 +3527,8 @@ std::vector<std::string>
InStream::readTokens(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) {
pattern p(ptrn);
__testlib_readMany(readTokens, readWord(p, variablesName), std::string, true);
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

void InStream::readWordTo(std::string &result, const pattern &p, const std::string &variableName) {
Expand All @@ -3508,6 +3541,8 @@ void InStream::readWordTo(std::string &result, const pattern &p, const std::stri
quit(_wa, ("Token parameter [name=" + variableName + "] equals to \"" + __testlib_part(result) +
"\", doesn't correspond to pattern \"" + p.src() + "\"").c_str());
}
if (strict && !variableName.empty())
validator.addVariable(variableName);
}

void InStream::readWordTo(std::string &result, const std::string &ptrn, const std::string &variableName) {
Expand Down Expand Up @@ -3850,6 +3885,7 @@ long long InStream::readLong(long long minv, long long maxv, const std::string &
if (strict && !variableName.empty()) {
validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result));
validator.adjustConstantBounds(variableName, minv, maxv);
validator.addVariable(variableName);
}

return result;
Expand All @@ -3858,6 +3894,8 @@ long long InStream::readLong(long long minv, long long maxv, const std::string &
std::vector<long long>
InStream::readLongs(int size, long long minv, long long maxv, const std::string &variablesName, int indexBase) {
__testlib_readMany(readLongs, readLong(minv, maxv, variablesName), long long, true)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::vector<long long> InStream::readLongs(int size, int indexBase) {
Expand Down Expand Up @@ -3893,6 +3931,7 @@ InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, con
if (strict && !variableName.empty()) {
validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result));
validator.adjustConstantBounds(variableName, minv, maxv);
validator.addVariable(variableName);
}

return result;
Expand All @@ -3901,6 +3940,8 @@ InStream::readUnsignedLong(unsigned long long minv, unsigned long long maxv, con
std::vector<unsigned long long> InStream::readUnsignedLongs(int size, unsigned long long minv, unsigned long long maxv,
const std::string &variablesName, int indexBase) {
__testlib_readMany(readUnsignedLongs, readUnsignedLong(minv, maxv, variablesName), unsigned long long, true)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::vector<unsigned long long> InStream::readUnsignedLongs(int size, int indexBase) {
Expand Down Expand Up @@ -3941,6 +3982,7 @@ int InStream::readInt(int minv, int maxv, const std::string &variableName) {
if (strict && !variableName.empty()) {
validator.addBoundsHit(variableName, ValidatorBoundsHit(minv == result, maxv == result));
validator.adjustConstantBounds(variableName, minv, maxv);
validator.addVariable(variableName);
}

return result;
Expand All @@ -3952,6 +3994,8 @@ int InStream::readInteger(int minv, int maxv, const std::string &variableName) {

std::vector<int> InStream::readInts(int size, int minv, int maxv, const std::string &variablesName, int indexBase) {
__testlib_readMany(readInts, readInt(minv, maxv, variablesName), int, true)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::vector<int> InStream::readInts(int size, int indexBase) {
Expand All @@ -3960,6 +4004,8 @@ std::vector<int> InStream::readInts(int size, int indexBase) {

std::vector<int> InStream::readIntegers(int size, int minv, int maxv, const std::string &variablesName, int indexBase) {
__testlib_readMany(readIntegers, readInt(minv, maxv, variablesName), int, true)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::vector<int> InStream::readIntegers(int size, int indexBase) {
Expand Down Expand Up @@ -4005,6 +4051,7 @@ double InStream::readReal(double minv, double maxv, const std::string &variableN
doubleDelta(maxv, result) < ValidatorBoundsHit::EPS
));
validator.adjustConstantBounds(variableName, minv, maxv);
validator.addVariable(variableName);
}

return result;
Expand All @@ -4013,6 +4060,8 @@ double InStream::readReal(double minv, double maxv, const std::string &variableN
std::vector<double>
InStream::readReals(int size, double minv, double maxv, const std::string &variablesName, int indexBase) {
__testlib_readMany(readReals, readReal(minv, maxv, variablesName), double, true)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::vector<double> InStream::readReals(int size, int indexBase) {
Expand All @@ -4026,6 +4075,8 @@ double InStream::readDouble(double minv, double maxv, const std::string &variabl
std::vector<double>
InStream::readDoubles(int size, double minv, double maxv, const std::string &variablesName, int indexBase) {
__testlib_readMany(readDoubles, readDouble(minv, maxv, variablesName), double, true)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::vector<double> InStream::readDoubles(int size, int indexBase) {
Expand Down Expand Up @@ -4066,6 +4117,7 @@ double InStream::readStrictReal(double minv, double maxv,
doubleDelta(maxv, result) < ValidatorBoundsHit::EPS
));
validator.adjustConstantBounds(variableName, minv, maxv);
validator.addVariable(variableName);
}

return result;
Expand All @@ -4077,6 +4129,8 @@ std::vector<double> InStream::readStrictReals(int size, double minv, double maxv
__testlib_readMany(readStrictReals,
readStrictReal(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName),
double, true)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

double InStream::readStrictDouble(double minv, double maxv,
Expand All @@ -4093,6 +4147,8 @@ std::vector<double> InStream::readStrictDoubles(int size, double minv, double ma
__testlib_readMany(readStrictDoubles,
readStrictDouble(minv, maxv, minAfterPointDigitCount, maxAfterPointDigitCount, variablesName),
double, true)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

bool InStream::eof() {
Expand Down Expand Up @@ -4251,6 +4307,8 @@ void InStream::readStringTo(std::string &result, const pattern &p, const std::st
__testlib_part(result) + "\", doesn't correspond to pattern \"" + p.src() + "\"").c_str());
}
}
if (strict && !variableName.empty())
validator.addVariable(variableName);
}

void InStream::readStringTo(std::string &result, const std::string &ptrn, const std::string &variableName) {
Expand All @@ -4265,6 +4323,8 @@ std::string InStream::readString(const pattern &p, const std::string &variableNa
std::vector<std::string>
InStream::readStrings(int size, const pattern &p, const std::string &variablesName, int indexBase) {
__testlib_readMany(readStrings, readString(p, variablesName), std::string, false)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::string InStream::readString(const std::string &ptrn, const std::string &variableName) {
Expand All @@ -4276,6 +4336,8 @@ std::vector<std::string>
InStream::readStrings(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) {
pattern p(ptrn);
__testlib_readMany(readStrings, readString(p, variablesName), std::string, false)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

void InStream::readLineTo(std::string &result) {
Expand Down Expand Up @@ -4305,6 +4367,8 @@ std::string InStream::readLine(const pattern &p, const std::string &variableName
std::vector<std::string>
InStream::readLines(int size, const pattern &p, const std::string &variablesName, int indexBase) {
__testlib_readMany(readLines, readString(p, variablesName), std::string, false)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

std::string InStream::readLine(const std::string &ptrn, const std::string &variableName) {
Expand All @@ -4315,6 +4379,8 @@ std::vector<std::string>
InStream::readLines(int size, const std::string &ptrn, const std::string &variablesName, int indexBase) {
pattern p(ptrn);
__testlib_readMany(readLines, readString(p, variablesName), std::string, false)
if (strict && !variablesName.empty())
validator.addVariable(variablesName);
}

#ifdef __GNUC__
Expand Down
6 changes: 6 additions & 0 deletions tests/test-007_validators/refs/v1-01/stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"a": min-value-hit max-value-hit
"n":
"t": min-value-hit
constant-bounds "a": 1 2
constant-bounds "n": 1 4
constant-bounds "t": 1 3
variable "a"
variable "n"
variable "t"
6 changes: 6 additions & 0 deletions tests/test-007_validators/refs/v1-02/stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"a": min-value-hit max-value-hit
"n": min-value-hit max-value-hit
"t": max-value-hit
constant-bounds "a": 1 ?
constant-bounds "n": 1 4
constant-bounds "t": 1 3
variable "a"
variable "n"
variable "t"
6 changes: 6 additions & 0 deletions tests/test-007_validators/refs/v1-04/stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"a": min-value-hit max-value-hit
"n":
"t":
constant-bounds "a": 1 ?
constant-bounds "n": 1 4
constant-bounds "t": 1 3
variable "a"
variable "n"
variable "t"
6 changes: 6 additions & 0 deletions tests/test-007_validators/refs/v1-06/stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"a": min-value-hit max-value-hit
"n": max-value-hit
"t":
constant-bounds "a": 1 4
constant-bounds "n": 1 4
constant-bounds "t": 1 3
variable "a"
variable "n"
variable "t"
6 changes: 6 additions & 0 deletions tests/test-007_validators/refs/v2-01/stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"a": min-value-hit max-value-hit
"n": max-value-hit
"t": min-value-hit
constant-bounds "a": 1 2
constant-bounds "n": 1 4
constant-bounds "t": 1 3
variable "a"
variable "n"
variable "t"
6 changes: 6 additions & 0 deletions tests/test-007_validators/refs/v2-02/stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"a": min-value-hit max-value-hit
"n": min-value-hit max-value-hit
"t": min-value-hit max-value-hit
constant-bounds "a": 1 ?
constant-bounds "n": 1 4
constant-bounds "t": 1 3
variable "a"
variable "n"
variable "t"
6 changes: 6 additions & 0 deletions tests/test-007_validators/refs/v2-04/stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"a": min-value-hit max-value-hit
"n": max-value-hit
"t": min-value-hit
constant-bounds "a": 1 ?
constant-bounds "n": 1 4
constant-bounds "t": 1 3
variable "a"
variable "n"
variable "t"
6 changes: 6 additions & 0 deletions tests/test-007_validators/refs/v2-06/stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"a": min-value-hit max-value-hit
"n": max-value-hit
"t": min-value-hit
constant-bounds "a": 1 4
constant-bounds "n": 1 4
constant-bounds "t": 1 3
variable "a"
variable "n"
variable "t"
10 changes: 10 additions & 0 deletions tests/test-007_validators/refs/v3-01/stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
"n": min-value-hit
"r":
"t": min-value-hit max-value-hit
constant-bounds "a": 1 2
constant-bounds "l": -2 2
constant-bounds "n": 1 4
constant-bounds "r": -5 5
constant-bounds "t": 1 3
variable "a"
variable "l"
variable "n"
variable "r"
variable "t"
10 changes: 10 additions & 0 deletions tests/test-007_validators/refs/v3-02/stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
"n": min-value-hit max-value-hit
"r":
"t": min-value-hit max-value-hit
constant-bounds "a": 1 ?
constant-bounds "l": -2 2
constant-bounds "n": 1 4
constant-bounds "r": -5 5
constant-bounds "t": 1 3
variable "a"
variable "l"
variable "n"
variable "r"
variable "t"
Loading

0 comments on commit 36041fc

Please sign in to comment.