Class MeasurementSet
- Namespace
- MetricsAssertions
- Assembly
- MetricsAssertions.dll
An immutable, queryable set of captured measurements - the core unit assertions are written against. Produced by an InstrumentCapture or MeterCapture and narrowed with Tagged(string, object?) / ForInstrument(string). Exposes counter-style aggregates (Total), histogram-style aggregates (Sum/Min/Max/ Average), the raw Values and All measurements, and a deterministic ToSnapshotString() projection for snapshot-style baselines.
public sealed class MeasurementSet
- Inheritance
-
MeasurementSet
- Inherited Members
- Extension Methods
Constructors
MeasurementSet(IEnumerable<CapturedMeasurement>)
Creates a set over the supplied measurements (defensively copied).
public MeasurementSet(IEnumerable<CapturedMeasurement> measurements)
Parameters
measurementsIEnumerable<CapturedMeasurement>The measurements in the set.
Properties
All
Gets every measurement in the set, in capture order.
public IReadOnlyList<CapturedMeasurement> All { get; }
Property Value
Average
Gets the mean of all values (0 when empty).
public double Average { get; }
Property Value
Count
Gets the number of measurements in the set.
public int Count { get; }
Property Value
Empty
An empty set.
public static MeasurementSet Empty { get; }
Property Value
IsEmpty
Gets whether the set contains no measurements.
public bool IsEmpty { get; }
Property Value
LastValue
Gets the most recently captured value, or null when the set is empty.
public double? LastValue { get; }
Property Value
Max
Gets the largest value (0 when empty).
public double Max { get; }
Property Value
Min
Gets the smallest value (0 when empty).
public double Min { get; }
Property Value
Sum
Gets the sum of all values (0 when empty).
public double Sum { get; }
Property Value
Total
Gets the net total of all values as a long (a counter / up-down-counter total).
public long Total { get; }
Property Value
Remarks
The sum is rounded to the nearest long using banker's rounding
(round half to even), so a Counter<double> whose values sum to a fractional total is
evaluated as an integer. For an exact fractional total compare Sum directly, or use
the histogram aggregate HasSampleSum(expected, tolerance) on the measurement set.
Values
Gets the individual measured values, in capture order.
public IReadOnlyList<double> Values { get; }
Property Value
Methods
AllValuesInRange(double, double)
Returns whether all values lie within the inclusive range [min, max].
public bool AllValuesInRange(double min, double max)
Parameters
Returns
Describe()
Renders every measurement on its own line (instrument, value, tags, timestamp) in capture order for failure diagnostics, or a placeholder when the set is empty. Unlike ToSnapshotString() (sorted, for stable baselines), this preserves capture order and carries timestamps.
public string Describe()
Returns
EveryMeasurementCarriesTag(string)
Returns whether every measurement in the set carries a tag with the given key.
public bool EveryMeasurementCarriesTag(string key)
Parameters
keystringThe tag key that must be present on every measurement.
Returns
ForInstrument(string)
Returns the subset emitted by the named instrument.
public MeasurementSet ForInstrument(string instrumentName)
Parameters
instrumentNamestringThe instrument name to filter by.
Returns
SamplesEqual(IReadOnlyList<double>, double)
Returns whether the values equal expected in order, each within
tolerance (absolute).
public bool SamplesEqual(IReadOnlyList<double> expected, double tolerance)
Parameters
expectedIReadOnlyList<double>The expected samples, in order.
tolerancedoubleThe allowed absolute difference per sample.
Returns
Exceptions
- ArgumentOutOfRangeException
toleranceis negative or non-finite.
SamplesEqual(params double[])
Returns whether the values equal expected in order.
public bool SamplesEqual(params double[] expected)
Parameters
expecteddouble[]The expected samples, in order.
Returns
SamplesEquivalentTo(IReadOnlyList<double>, double)
Returns whether the values equal expected regardless of order, each
within tolerance (absolute). Both sequences are sorted and compared
element by element, so equal counts and pairwise-within-tolerance values match.
public bool SamplesEquivalentTo(IReadOnlyList<double> expected, double tolerance)
Parameters
expectedIReadOnlyList<double>The expected samples, in any order.
tolerancedoubleThe allowed absolute difference per sample.
Returns
Exceptions
- ArgumentOutOfRangeException
toleranceis negative or non-finite.
SamplesEquivalentTo(params double[])
Returns whether the values equal expected regardless of order.
public bool SamplesEquivalentTo(params double[] expected)
Parameters
expecteddouble[]The expected samples, in any order.
Returns
Tagged(string, object?)
Returns the subset whose measurements carry a tag key equal to value.
public MeasurementSet Tagged(string key, object? value)
Parameters
Returns
Tagged(params (string Key, object? Value)[])
Returns the subset whose measurements carry all of the supplied tags.
public MeasurementSet Tagged(params (string Key, object? Value)[] tags)
Parameters
Returns
ToSnapshotString()
Returns a deterministic, human-readable projection of the set (one line per measurement, sorted by instrument, value, then tags) suitable for snapshot-style baselines via a snapshot assertion library.
public string ToSnapshotString()