23 Condition (
bool result):
27 "Condition (" + toString (result) +
')',
49 bool getResult()
const
55 const char* getFile()
const
73 bool hasDetailedMetadata()
const
75 return m_hasDetailedMetadata;
79 void representWithTokens (std::ostream& stream)
const
81 stream << m_tokenRepresentation;
85 void representWithStringRepresentations (std::ostream& stream)
const
87 stream << m_stringRepresentation;
92 template <
typename ValueType>
93 static Condition truth (ValueType&& value,
const char* valueTokens,
const char* file,
int line)
95 std::ostringstream tokenRepresentationStream;
96 std::ostringstream stringRepresentationStream;
97 tokenRepresentationStream <<
"HART_TRUE (" << valueTokens <<
")";
98 stringRepresentationStream <<
"HART_TRUE (" <<
hart::toString (value) <<
")";
99 return Condition (
static_cast<
bool> (value), tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
104 template <
typename ValueType>
105 static Condition falsehood (ValueType&& value,
const char* valueTokens,
const char* file,
int line)
107 std::ostringstream tokenRepresentationStream;
108 std::ostringstream stringRepresentationStream;
109 tokenRepresentationStream <<
"HART_FALSE (" << valueTokens <<
")";
110 stringRepresentationStream <<
"HART_FALSE (" <<
hart::toString (value) <<
")";
111 return Condition (!
static_cast<
bool> (value), tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
116 template <
typename LHSType,
typename RHSType>
117 static Condition equals (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
119 std::ostringstream tokenRepresentationStream;
120 std::ostringstream stringRepresentationStream;
121 tokenRepresentationStream <<
"HART_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
")";
122 stringRepresentationStream <<
"HART_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
123 return Condition (lhs == rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
128 template <
typename LHSType,
typename RHSType>
129 static Condition notEquals (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
131 std::ostringstream tokenRepresentationStream;
132 std::ostringstream stringRepresentationStream;
133 tokenRepresentationStream <<
"HART_NOT_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
")";
134 stringRepresentationStream <<
"HART_NOT_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
135 return Condition (lhs != rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
139 template <
typename FloatType>
140 static typename std::enable_if<std::is_floating_point<FloatType>::value,
Condition>::type
145 const char* lhsTokens,
146 const char* rhsTokens,
147 const char* toleranceTokens,
152 std::ostringstream tokenRepresentationStream;
153 std::ostringstream stringRepresentationStream;
154 tokenRepresentationStream <<
"HART_FLOAT_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
", " << toleranceTokens <<
")";
155 stringRepresentationStream <<
"HART_FLOAT_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
", " <<
hart::toString (tolerance) <<
")";
157 lhs - tolerance <= rhs && rhs <= lhs + tolerance,
158 tokenRepresentationStream.str(),
159 stringRepresentationStream.str(),
166 template <
typename FloatType>
167 static typename std::enable_if<std::is_floating_point<FloatType>::value,
Condition>::type
172 const char* lhsTokens,
173 const char* rhsTokens,
174 const char* toleranceTokens,
179 std::ostringstream tokenRepresentationStream;
180 std::ostringstream stringRepresentationStream;
181 tokenRepresentationStream <<
"HART_FLOAT_NOT_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
", " << toleranceTokens <<
")";
182 stringRepresentationStream <<
"HART_FLOAT_NOT_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
", " <<
hart::toString (tolerance) <<
")";
184 lhs - tolerance > rhs || rhs > lhs + tolerance,
185 tokenRepresentationStream.str(),
186 stringRepresentationStream.str(),
195 double observedFrequencyHz,
196 double expectedFrequencyHz,
197 double toleranceCents,
198 const char* observedFrequencyTokens,
199 const char* expectedFrequencyTokens,
200 const char* toleranceTokens,
205 std::ostringstream tokenRepresentationStream;
206 std::ostringstream stringRepresentationStream;
207 tokenRepresentationStream <<
"HART_FREQUENCIES_EQUAL (" << observedFrequencyTokens <<
", " << expectedFrequencyTokens <<
", " << toleranceTokens <<
')';
208 stringRepresentationStream <<
"HART_FREQUENCIES_EQUAL (" <<
hart::toString (observedFrequencyHz) <<
", " <<
hart::toString (expectedFrequencyHz) <<
", " <<
hart::toString (toleranceCents) <<
')';
210 (observedFrequencyHz >=
addCents (expectedFrequencyHz
, -toleranceCents
)) && (observedFrequencyHz <=
addCents (expectedFrequencyHz
, toleranceCents
)),
211 tokenRepresentationStream.str(),
212 stringRepresentationStream.str(),
220 frequenciesNotEqual (
221 double observedFrequencyHz,
222 double expectedFrequencyHz,
223 double toleranceCents,
224 const char* observedFrequencyTokens,
225 const char* expectedFrequencyTokens,
226 const char* toleranceTokens,
231 std::ostringstream tokenRepresentationStream;
232 std::ostringstream stringRepresentationStream;
233 tokenRepresentationStream <<
"HART_FREQUENCIES_NOT_EQUAL (" << observedFrequencyTokens <<
", " << expectedFrequencyTokens <<
", " << toleranceTokens <<
')';
234 stringRepresentationStream <<
"HART_FREQUENCIES_NOT_EQUAL (" <<
hart::toString (observedFrequencyHz) <<
", " <<
hart::toString (expectedFrequencyHz) <<
", " <<
hart::toString (toleranceCents) <<
')';
236 ! ((observedFrequencyHz >=
addCents (expectedFrequencyHz
, -toleranceCents
)) && (observedFrequencyHz <=
addCents (expectedFrequencyHz
, toleranceCents
))),
237 tokenRepresentationStream.str(),
238 stringRepresentationStream.str(),
245 template <
typename LHSType,
typename RHSType>
246 static Condition greaterThan (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
248 std::ostringstream tokenRepresentationStream;
249 std::ostringstream stringRepresentationStream;
250 tokenRepresentationStream <<
"HART_GREATER_THAN (" << lhsTokens <<
", " << rhsTokens <<
")";
251 stringRepresentationStream <<
"HART_GREATER_THAN (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
252 return Condition (lhs > rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
256 template <
typename LHSType,
typename RHSType>
257 static Condition greaterOrEqual (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
259 std::ostringstream tokenRepresentationStream;
260 std::ostringstream stringRepresentationStream;
261 tokenRepresentationStream <<
"HART_GREATER_OR_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
")";
262 stringRepresentationStream <<
"HART_GREATER_OR_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
263 return Condition (lhs >= rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
267 template <
typename LHSType,
typename RHSType>
268 static Condition lessThan (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
270 std::ostringstream tokenRepresentationStream;
271 std::ostringstream stringRepresentationStream;
272 tokenRepresentationStream <<
"HART_LESS_THAN (" << lhsTokens <<
", " << rhsTokens <<
")";
273 stringRepresentationStream <<
"HART_LESS_THAN (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
274 return Condition (lhs < rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
278 template <
typename LHSType,
typename RHSType>
279 static Condition lessOrEqual (LHSType&& lhs, RHSType&& rhs,
const char* lhsTokens,
const char* rhsTokens,
const char* file,
int line)
281 std::ostringstream tokenRepresentationStream;
282 std::ostringstream stringRepresentationStream;
283 tokenRepresentationStream <<
"HART_LESS_OR_EQUAL (" << lhsTokens <<
", " << rhsTokens <<
")";
284 stringRepresentationStream <<
"HART_LESS_OR_EQUAL (" <<
hart::toString (lhs) <<
", " <<
hart::toString (rhs) <<
")";
285 return Condition (lhs <= rhs, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
289 template <
typename ValueType,
typename BoundType>
292 BoundType&& minValue,
293 BoundType&& maxValue,
294 const char* valueTokens,
295 const char* minValueTokens,
296 const char* maxValueTokens,
301 std::ostringstream tokenRepresentationStream;
302 std::ostringstream stringRepresentationStream;
303 tokenRepresentationStream <<
"HART_IN_RANGE (" << valueTokens <<
", " << minValueTokens <<
", " << maxValueTokens <<
")";
304 stringRepresentationStream <<
"HART_IN_RANGE (" <<
hart::toString (value) <<
", " <<
hart::toString (minValue) <<
", " <<
hart::toString (maxValue) <<
")";
305 return Condition (minValue <= value && value <= maxValue, tokenRepresentationStream.str(), stringRepresentationStream.str(), file, line);
309 template <
typename FloatType>
310 static typename std::enable_if<std::is_floating_point<FloatType>::value,
Condition>::type
316 const char* valueTokens,
317 const char* minValueTokens,
318 const char* maxValueTokens,
319 const char* toleranceTokens,
324 std::ostringstream tokenRepresentationStream;
325 std::ostringstream stringRepresentationStream;
326 tokenRepresentationStream <<
"HART_FLOAT_IN_RANGE (" << valueTokens <<
", " << minValueTokens <<
", " << maxValueTokens <<
", " << toleranceTokens <<
")";
327 stringRepresentationStream <<
"HART_FLOAT_IN_RANGE (" <<
hart::toString (value) <<
", " <<
hart::toString (minValue) <<
", " <<
hart::toString (maxValue) <<
", " <<
hart::toString (tolerance) <<
")";
329 minValue - tolerance <= value && value <= maxValue + tolerance,
330 tokenRepresentationStream.str(),
331 stringRepresentationStream.str(),
338 Condition (
bool result, std::string tokenRepresentation, std::string stringRepresentation,
const char* file,
int line,
bool hasDetailedMetadata =
true) :
340 m_hasDetailedMetadata (hasDetailedMetadata),
341 m_tokenRepresentation (std::move (tokenRepresentation)),
342 m_stringRepresentation (std::move (stringRepresentation)),
349 bool m_hasDetailedMetadata;
350 std::string m_tokenRepresentation;
351 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.