24 Condition (
bool result):
28 "Condition (" + toString (result) +
')',
50 bool getResult()
const
56 const char* getFile()
const
74 bool hasDetailedMetadata()
const
76 return m_hasDetailedMetadata;
80 void representWithTokens (std::ostream& stream)
const
82 stream << m_tokenRepresentation;
86 void representWithStringRepresentations (std::ostream& stream)
const
88 stream << m_stringRepresentation;
93 template <
typename ValueType>
94 static Condition truth (ValueType&& value,
const char* valueTokens,
const char* file,
int line)
96 std::ostringstream tokenRepresentationStream;
97 std::ostringstream stringRepresentationStream;
98 tokenRepresentationStream <<
"HART_TRUE (" << valueTokens <<
")";
99 stringRepresentationStream <<
"HART_TRUE (" <<
hart::toString (value) <<
")";
100 return Condition (
static_cast<
bool> (value), tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
105 template <
typename ValueType>
106 static Condition falsehood (ValueType&& value,
const char* valueTokens,
const char* file,
int line)
108 std::ostringstream tokenRepresentationStream;
109 std::ostringstream stringRepresentationStream;
110 tokenRepresentationStream <<
"HART_FALSE (" << valueTokens <<
")";
111 stringRepresentationStream <<
"HART_FALSE (" <<
hart::toString (value) <<
")";
112 return Condition (!
static_cast<
bool> (value), tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
117 template <
typename LHSType,
typename RHSType>
118 static Condition equals (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
120 std::ostringstream tokenRepresentationStream;
121 std::ostringstream stringRepresentationStream;
122 tokenRepresentationStream <<
"HART_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
")";
123 stringRepresentationStream <<
"HART_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
124 return Condition (lhs == rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
129 template <
typename LHSType,
typename RHSType>
130 static Condition notEquals (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
132 std::ostringstream tokenRepresentationStream;
133 std::ostringstream stringRepresentationStream;
134 tokenRepresentationStream <<
"HART_NOT_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
")";
135 stringRepresentationStream <<
"HART_NOT_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
136 return Condition (lhs != rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
140 template <
typename FloatType>
141 static typename std::enable_if<std::is_floating_point<FloatType>::value,
Condition>::type
146 const char* lhsTokens,
147 const char* rhsTokens,
148 const char* toleranceTokens,
153 std::ostringstream tokenRepresentationStream;
154 std::ostringstream stringRepresentationStream;
155 tokenRepresentationStream <<
"HART_FLOAT_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
", " << toleranceTokens <<
")";
156 stringRepresentationStream <<
"HART_FLOAT_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
", " <<
hart::toString (tolerance) <<
")";
158 lhs - tolerance <= rhs && rhs <= lhs + tolerance,
159 tokenRepresentationStream.str(),
160 stringRepresentationStream.str(),
167 template <
typename FloatType>
168 static typename std::enable_if<std::is_floating_point<FloatType>::value,
Condition>::type
173 const char* lhsTokens,
174 const char* rhsTokens,
175 const char* toleranceTokens,
180 std::ostringstream tokenRepresentationStream;
181 std::ostringstream stringRepresentationStream;
182 tokenRepresentationStream <<
"HART_FLOAT_NOT_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
", " << toleranceTokens <<
")";
183 stringRepresentationStream <<
"HART_FLOAT_NOT_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
", " <<
hart::toString (tolerance) <<
")";
185 lhs - tolerance > rhs || rhs > lhs + tolerance,
186 tokenRepresentationStream.str(),
187 stringRepresentationStream.str(),
196 double observedFrequencyHz,
197 double expectedFrequencyHz,
198 double toleranceCents,
199 const char* observedFrequencyTokens,
200 const char* expectedFrequencyTokens,
201 const char* toleranceTokens,
206 std::ostringstream tokenRepresentationStream;
207 std::ostringstream stringRepresentationStream;
208 tokenRepresentationStream <<
"HART_FREQUENCIES_EQUAL (" << observedFrequencyTokens <<
", " << expectedFrequencyTokens <<
", " << toleranceTokens <<
')';
209 stringRepresentationStream <<
"HART_FREQUENCIES_EQUAL (" <<
hart::toString (observedFrequencyHz) <<
", " <<
hart::toString (expectedFrequencyHz) <<
", " <<
hart::toString (toleranceCents) <<
')';
211 (observedFrequencyHz >=
addCents (expectedFrequencyHz
, -toleranceCents
)) && (observedFrequencyHz <=
addCents (expectedFrequencyHz
, toleranceCents
)),
212 tokenRepresentationStream.str(),
213 stringRepresentationStream.str(),
221 frequenciesNotEqual (
222 double observedFrequencyHz,
223 double expectedFrequencyHz,
224 double toleranceCents,
225 const char* observedFrequencyTokens,
226 const char* expectedFrequencyTokens,
227 const char* toleranceTokens,
232 std::ostringstream tokenRepresentationStream;
233 std::ostringstream stringRepresentationStream;
234 tokenRepresentationStream <<
"HART_FREQUENCIES_NOT_EQUAL (" << observedFrequencyTokens <<
", " << expectedFrequencyTokens <<
", " << toleranceTokens <<
')';
235 stringRepresentationStream <<
"HART_FREQUENCIES_NOT_EQUAL (" <<
hart::toString (observedFrequencyHz) <<
", " <<
hart::toString (expectedFrequencyHz) <<
", " <<
hart::toString (toleranceCents) <<
')';
237 ! ((observedFrequencyHz >=
addCents (expectedFrequencyHz
, -toleranceCents
)) && (observedFrequencyHz <=
addCents (expectedFrequencyHz
, toleranceCents
))),
238 tokenRepresentationStream.str(),
239 stringRepresentationStream.str(),
246 template <
typename LHSType,
typename RHSType>
247 static Condition greaterThan (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
249 std::ostringstream tokenRepresentationStream;
250 std::ostringstream stringRepresentationStream;
251 tokenRepresentationStream <<
"HART_GREATER_THAN (" << lhsTokens <<
", " << rhsTokens <<
")";
252 stringRepresentationStream <<
"HART_GREATER_THAN (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
253 return Condition (lhs > rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
257 template <
typename LHSType,
typename RHSType>
258 static Condition greaterOrEqual (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
260 std::ostringstream tokenRepresentationStream;
261 std::ostringstream stringRepresentationStream;
262 tokenRepresentationStream <<
"HART_GREATER_OR_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
")";
263 stringRepresentationStream <<
"HART_GREATER_OR_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
264 return Condition (lhs >= rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
268 template <
typename LHSType,
typename RHSType>
269 static Condition lessThan (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
271 std::ostringstream tokenRepresentationStream;
272 std::ostringstream stringRepresentationStream;
273 tokenRepresentationStream <<
"HART_LESS_THAN (" << lhsTokens <<
", " << rhsTokens <<
")";
274 stringRepresentationStream <<
"HART_LESS_THAN (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
275 return Condition (lhs < rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
279 template <
typename LHSType,
typename RHSType>
280 static Condition lessOrEqual (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
282 std::ostringstream tokenRepresentationStream;
283 std::ostringstream stringRepresentationStream;
284 tokenRepresentationStream <<
"HART_LESS_OR_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
")";
285 stringRepresentationStream <<
"HART_LESS_OR_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
286 return Condition (lhs <= rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
290 template <
typename ValueType,
typename BoundType>
293 BoundType&& minValue,
294 BoundType&& maxValue,
295 const char* valueTokens,
296 const char* minValueTokens,
297 const char* maxValueTokens,
302 std::ostringstream tokenRepresentationStream;
303 std::ostringstream stringRepresentationStream;
304 tokenRepresentationStream <<
"HART_IN_RANGE (" << valueTokens <<
", " << minValueTokens <<
", " << maxValueTokens <<
")";
305 stringRepresentationStream <<
"HART_IN_RANGE (" <<
hart::toString (value) <<
", " <<
hart::toString (minValue) <<
", " <<
hart::toString (maxValue) <<
")";
306 return Condition (minValue <= value && value <= maxValue, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
310 template <
typename FloatType>
311 static typename std::enable_if<std::is_floating_point<FloatType>::value,
Condition>::type
317 const char* valueTokens,
318 const char* minValueTokens,
319 const char* maxValueTokens,
320 const char* toleranceTokens,
325 std::ostringstream tokenRepresentationStream;
326 std::ostringstream stringRepresentationStream;
327 tokenRepresentationStream <<
"HART_FLOAT_IN_RANGE (" << valueTokens <<
", " << minValueTokens <<
", " << maxValueTokens <<
", " << toleranceTokens <<
")";
328 stringRepresentationStream <<
"HART_FLOAT_IN_RANGE (" <<
hart::toString (value) <<
", " <<
hart::toString (minValue) <<
", " <<
hart::toString (maxValue) <<
", " <<
hart::toString (tolerance) <<
")";
330 minValue - tolerance <= value && value <= maxValue + tolerance,
331 tokenRepresentationStream.str(),
332 stringRepresentationStream.str(),
339 template <
typename FloatType>
340 static typename std::enable_if<std::is_floating_point<FloatType>::value,
Condition>::type
343 const char* valueTokens,
348 std::ostringstream tokenRepresentationStream;
349 std::ostringstream stringRepresentationStream;
350 tokenRepresentationStream <<
"HART_IS_NAN (" << valueTokens <<
')';
351 stringRepresentationStream <<
"HART_IS_NAN (" <<
hart::toString (value) <<
')';
354 tokenRepresentationStream.str(),
355 stringRepresentationStream.str(),
362 template <
typename FloatType>
363 static typename std::enable_if<std::is_floating_point<FloatType>::value,
Condition>::type
366 const char* valueTokens,
371 std::ostringstream tokenRepresentationStream;
372 std::ostringstream stringRepresentationStream;
373 tokenRepresentationStream <<
"HART_NOT_NAN (" << valueTokens <<
')';
374 stringRepresentationStream <<
"HART_NOT_NAN (" <<
hart::toString (value) <<
')';
376 ! std::isnan (value),
377 tokenRepresentationStream.str(),
378 stringRepresentationStream.str(),
385 Condition (
bool result, std::string tokenRepresentation, std::string stringRepresentation,
const char* file,
int line,
bool hasDetailedMetadata =
true) :
387 m_hasDetailedMetadata (hasDetailedMetadata),
388 m_tokenRepresentation (std::move (tokenRepresentation)),
389 m_stringRepresentation (std::move (stringRepresentation)),
396 bool m_hasDetailedMetadata;
397 std::string m_tokenRepresentation;
398 std::string m_stringRepresentation;
A class representing some condition.
double addCents(double baseFrequencyHz, double cents)
Anns an offset in cents to a frequency in Hz.